jhorstmann commented on PR #8543:
URL: https://github.com/apache/arrow-rs/pull/8543#issuecomment-3365277381
I think the benchmark results for `from_iter` might be a bit overly
optimistic, the input in the benchmark seems to be already be in an
`Vec<Option<bool>>`, the rust compiler would be able to optimize the
intermediate vector allocation away. The performance for an arbitrary iterator
might be worse. An implementation using the existing `BooleanBuilder` might be
preferrable for the generic case, and users with an trusted iterator
implementation should be directed to the new `unsafe` implementation.
```rust
impl<Ptr: std::borrow::Borrow<Option<bool>>> FromIterator<Ptr> for
BooleanArray {
fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self {
let iter = iter.into_iter();
let capacity = match iter.size_hint() {
(lower, Some(upper)) if lower == upper => lower,
_ => 0
};
let mut builder = BooleanBuilder::with_capacity(capacity);
builder.extend(iter.map(|item| *item.borrow()));
builder.finish()
}
}
```
This is probably much slower than the current incorrect implementation, but
any optimizations to `BooleanBuilder` would then also apply to this
implementation.
--
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]