@@ -461,11 +461,13 @@ impl<T> BufferMut<T> {
461461 . checked_mul ( size_of :: < T > ( ) )
462462 . vortex_expect ( "buffer capacity overflow" ) ;
463463 let physical_alignment = max ( self . alignment , self . physical_alignment ) ;
464- let required_size = required_size
464+ let current_size = self . allocation . size ( ) - self . offset ;
465+ let logical_size = required_size
466+ . max ( current_size. saturating_mul ( 2 ) )
467+ . max ( physical_alignment. as_usize ( ) ) ;
468+ let allocation_size = logical_size
465469 . checked_add ( physical_alignment. as_usize ( ) )
466470 . vortex_expect ( "buffer capacity overflow" ) ;
467- let current_size = self . allocation . size ( ) - self . offset ;
468- let allocation_size = required_size. max ( current_size. saturating_mul ( 2 ) ) ;
469471 let allocation_alignment = if self . allocation . size ( ) == 0 {
470472 1
471473 } else {
@@ -1084,6 +1086,19 @@ mod test {
10841086 assert_eq ! ( buffer. as_slice( ) , ( 0 ..10_000 ) . collect:: <Vec <_>>( ) ) ;
10851087 }
10861088
1089+ #[ test]
1090+ fn growth_seeds_and_doubles_logical_capacity ( ) {
1091+ let alignment = Alignment :: new ( 64 ) ;
1092+ let mut buffer = BufferMut :: < u8 > :: empty_aligned ( alignment) ;
1093+
1094+ buffer. push ( 0 ) ;
1095+ let capacity = buffer. capacity ( ) ;
1096+ assert ! ( capacity >= alignment. as_usize( ) ) ;
1097+
1098+ buffer. reserve ( capacity) ;
1099+ assert ! ( buffer. capacity( ) >= capacity * 2 ) ;
1100+ }
1101+
10871102 #[ test]
10881103 fn from_iter ( ) {
10891104 let buf = BufferMut :: from_iter ( [ 0 , 10 , 20 , 30 ] ) ;
0 commit comments