@@ -122,21 +122,20 @@ impl BlobVec {
122
122
/// Reserves the minimum capacity for at least `additional` more elements to be inserted in the given `BlobVec`.
123
123
#[ inline]
124
124
pub fn reserve ( & mut self , additional : usize ) {
125
- if self . capacity - self . len < additional {
126
- self . do_reserve ( additional) ;
125
+ /// Similar to `reserve_exact`. This method ensures that the capacity will grow at least `self.capacity()` if there is no
126
+ /// enough space to hold `additional` more elements.
127
+ #[ cold]
128
+ fn do_reserve ( slf : & mut BlobVec , additional : usize ) {
129
+ if slf. item_layout . size ( ) > 0 {
130
+ let increment = slf. capacity . max ( additional - ( slf. capacity - slf. len ) ) ;
131
+ let increment = NonZeroUsize :: new ( increment) . unwrap ( ) ;
132
+ // SAFETY: not called for ZSTs
133
+ unsafe { slf. grow_exact ( increment) } ;
134
+ }
127
135
}
128
- }
129
136
130
- /// Similar to `reserve_exact`. This method ensures that the capacity will grow at least `self.capacity()` if there is no
131
- /// enough space to hold `additional` more elements.
132
- #[ cold]
133
- fn do_reserve ( & mut self , additional : usize ) {
134
- let available_space = self . capacity - self . len ;
135
- if available_space < additional && self . item_layout . size ( ) > 0 {
136
- let increment = self . capacity . max ( additional - available_space) ;
137
- let increment = NonZeroUsize :: new ( increment) . unwrap ( ) ;
138
- // SAFETY: not called for ZSTs
139
- unsafe { self . grow_exact ( increment) } ;
137
+ if self . capacity - self . len < additional {
138
+ do_reserve ( self , additional) ;
140
139
}
141
140
}
142
141
0 commit comments