Skip to content

Commit 13808a7

Browse files
Dandandanclaude
andcommitted
fix: Simplify BatchedVec::size() and fix misleading comments
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 439ee19 commit 13808a7

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

  • datafusion/functions-aggregate-common/src/aggregate/groups_accumulator

‎datafusion/functions-aggregate-common/src/aggregate/groups_accumulator/batched_vec.rs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ impl<T: Clone> BatchedVec<T> {
130130

131131
/// Take the first `n` elements (for `EmitTo::First(n)`).
132132
///
133-
/// When `n` equals `BATCH_SIZE`, this is zero-copy (just `mem::take`
134-
/// on the first batch). Otherwise, full batches are drained via
135-
/// `mem::take` (O(1) each) and only the split-point batch is copied.
133+
/// When `n` equals `BATCH_SIZE`, this is zero-copy (just returns
134+
/// the first batch's Vec). Otherwise elements are copied into a
135+
/// new Vec.
136136
pub fn take_first(&mut self, n: usize) -> Vec<T> {
137137
assert!(n <= self.len);
138138
let full_batches = n >> BATCH_SHIFT;
@@ -146,7 +146,7 @@ impl<T: Clone> BatchedVec<T> {
146146

147147
let mut result = Vec::with_capacity(n);
148148

149-
// Take full batches — O(1) each
149+
// Copy full batches into result
150150
for batch in self.batches.drain(..full_batches) {
151151
result.extend(batch);
152152
}
@@ -165,11 +165,7 @@ impl<T: Clone> BatchedVec<T> {
165165

166166
/// Total heap memory used by this structure.
167167
pub fn size(&self) -> usize {
168-
self.batches
169-
.iter()
170-
.map(|b| b.capacity() * size_of::<T>())
171-
.sum::<usize>()
172-
+ self.batches.capacity() * size_of::<Vec<T>>()
168+
self.len * size_of::<T>() + self.batches.capacity() * size_of::<Vec<T>>()
173169
}
174170
}
175171

0 commit comments

Comments
 (0)