alamb commented on code in PR #9132:
URL: https://github.com/apache/arrow-rs/pull/9132#discussion_r2678596706
##########
arrow-select/src/coalesce/byte_view.rs:
##########
@@ -98,7 +98,9 @@ impl<B: ByteViewType> InProgressByteViewArray<B> {
/// This is done on write (when we know it is necessary) rather than
/// eagerly to avoid allocations that are not used.
fn ensure_capacity(&mut self) {
- self.views.reserve(self.batch_size);
+ if self.views.capacity() == 0 {
Review Comment:
I think it would be easier to understand the preconditions of this code if
this also included a (debug) assert for existing capacuty
like
```rust
if self.views.capacity() == 0 {
self.views.reserve(self.batch_size)
}
debug_assert_eq!(self.views.capacity(), self.batch_size);
```
From just looking at this, I worry:
1. This could wipe out existing views (though w/ capacity zero that is
likely impossible)
2. Could potentially discard an existing allocation that is not sufficiently
sized
I don't think either of those is actually a problem today, but I can imagine
them potentially being violated in the future (for example if we ever allowed
coalesce to append more values than `batch_size)`
Another more future proof way might be simply
```rust
if self.views.capacty() < self.batch_size() {
self.views.reserve(self.batch_size - self.views.capacity())
}
```
--
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]