@@ -251,7 +251,7 @@ mod container {
251
251
fn length_in_bytes ( & self ) -> usize {
252
252
match self {
253
253
// We'll need one u64 for the length, then the length rounded up to a multiple of 8.
254
- Column :: Typed ( t) => t . as_bytes ( ) . map ( | ( _ , x ) | 8 * ( 1 + ( x . len ( ) / 8 ) + if x . len ( ) % 8 == 0 { 0 } else { 1 } ) ) . sum ( ) ,
254
+ Column :: Typed ( t) => 8 * t . length_in_words ( ) ,
255
255
Column :: Bytes ( b) => b. len ( ) ,
256
256
Column :: Align ( a) => 8 * a. len ( ) ,
257
257
}
@@ -304,10 +304,10 @@ mod builder {
304
304
fn push_into ( & mut self , item : T ) {
305
305
self . current . push ( item) ;
306
306
// If there is less than 10% slop with 2MB backing allocations, mint a container.
307
- let len : usize = self . current . as_bytes ( ) . map ( | ( _ , x ) | 8 * ( 1 + ( x . len ( ) / 8 ) + if x . len ( ) % 8 == 0 { 0 } else { 1 } ) ) . sum ( ) ;
308
- let up : usize = ( len + ( ( 1 << 20 ) - 1 ) ) & !( ( 1 << 20 ) - 1 ) ;
309
- if up - len < up / 10 {
310
- let mut alloc = Vec :: with_capacity ( up/ 8 ) ;
307
+ let words = self . current . length_in_words ( ) ;
308
+ let round = ( words + ( ( 1 << 18 ) - 1 ) ) & !( ( 1 << 18 ) - 1 ) ;
309
+ if round - words < round / 10 {
310
+ let mut alloc = Vec :: with_capacity ( round ) ;
311
311
columnar:: bytes:: serialization:: encode ( & mut alloc, self . current . as_bytes ( ) ) ;
312
312
self . pending . push_back ( Column :: Align ( alloc. into_boxed_slice ( ) ) ) ;
313
313
self . current . clear ( ) ;
0 commit comments