scovich commented on code in PR #9114:
URL: https://github.com/apache/arrow-rs/pull/9114#discussion_r2683051311
##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -967,15 +967,16 @@ impl<'a, T: ByteViewType + ?Sized> IntoIterator for &'a
GenericByteViewArray<T>
}
impl<T: ByteViewType + ?Sized> From<ArrayData> for GenericByteViewArray<T> {
- fn from(value: ArrayData) -> Self {
- let views = value.buffers()[0].clone();
- let views = ScalarBuffer::new(views, value.offset(), value.len());
- let buffers = value.buffers()[1..].to_vec().into();
+ fn from(data: ArrayData) -> Self {
+ let (_data_type, len, nulls, offset, mut buffers, _child_data) =
data.into_parts();
+ let views = buffers.remove(0); // need to maintain order of remaining
buffers
+ let buffers = buffers.into(); // convert to Arc
Review Comment:
I just realized... if the Arc is anyway copying the vec (which unfortunately
is required due to intrusive refcounts, unlike Box), it's annoyingly expensive
to `remove(0)` first. Is there a way to copy directly from `&buffers[1..]` to
`Arc<[]>` instead? Something like this?
```rust
let buffers = buffers.into_iter().skip(1).collect();
```
`Vec::IntoIter` implements`TrustedLen` and `ExactSizeIterator`, and `Skip`
conditionally implements those traits as well, which _should_ lead to this
optimization noted in
[Arc::from_iter](https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-FromIterator%3CT%3E-for-Arc%3C%5BT%5D%3E):
> When your Iterator implements `TrustedLen` and is of an exact size, a
single allocation will be made for the Arc<[T]>. For example:
> ```rust
> let evens: Arc<[u8]> = (0..10).collect(); // Just a single allocation
happens here.
> ```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]