File tree Expand file tree Collapse file tree
datafusion/functions-aggregate-common/src/aggregate/groups_accumulator Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments