@@ -289,7 +289,7 @@ impl<'a, T: 'a, const N: usize> Drop for Drain<'a, T, N> {
289289 let dst = ptr. add ( start) ;
290290 core:: ptr:: copy ( src, dst, self . 0 . tail_len ) ;
291291 }
292- source_vec. set_len ( start + self . 0 . tail_len ) ;
292+ source_vec. len . add ( self . 0 . tail_len ) ;
293293 }
294294 }
295295 }
@@ -308,7 +308,7 @@ impl<'a, T: 'a, const N: usize> Drop for Drain<'a, T, N> {
308308 unsafe {
309309 let vec = vec. as_mut ( ) ;
310310 let old_len = vec. len ( ) ;
311- vec. set_len ( old_len + drop_len + self . tail_len ) ;
311+ vec. len . add ( drop_len + self . tail_len ) ;
312312 vec. truncate ( old_len + self . tail_len ) ;
313313 }
314314
@@ -374,7 +374,7 @@ impl<T, const N: usize> Drain<'_, T, N> {
374374 if let Some ( new_item) = replace_with. next ( ) {
375375 unsafe {
376376 core:: ptr:: write ( place, new_item) ;
377- vec. set_len ( vec . len ( ) + 1 ) ;
377+ vec. len . add ( 1 ) ;
378378 }
379379 } else {
380380 return false ;
@@ -1137,7 +1137,7 @@ impl<T, const N: usize> SmallVec<T, N> {
11371137 debug_assert ! ( len < self . capacity( ) ) ;
11381138 // SAFETY: we have wrote the value to the address already
11391139 unsafe {
1140- self . len . increment ( ) ;
1140+ self . len . add ( 1 ) ;
11411141 }
11421142 }
11431143
@@ -1157,7 +1157,7 @@ impl<T, const N: usize> SmallVec<T, N> {
11571157 // SAFETY: new_len < len since len is non-zero and
11581158 // we are returning ownership of the current value.
11591159 unsafe {
1160- self . len . decrement ( ) ;
1160+ self . len . sub ( 1 ) ;
11611161 }
11621162 // SAFETY: this element was initialized and we just gave up ownership of
11631163 // it, so we can give it away
@@ -1188,7 +1188,7 @@ impl<T, const N: usize> SmallVec<T, N> {
11881188 // SAFETY: we have a mutable reference to each vector and each uniquely
11891189 // owns its memory. so the ranges can't overlap
11901190 unsafe { copy_nonoverlapping ( other. as_ptr ( ) , ptr, other_len) } ;
1191- unsafe { self . set_len ( total_len ) }
1191+ unsafe { self . len . add ( other_len ) }
11921192 }
11931193
11941194 #[ inline]
@@ -1388,7 +1388,7 @@ impl<T, const N: usize> SmallVec<T, N> {
13881388 let value = core:: ptr:: read ( self . as_ptr ( ) . add ( index) ) ;
13891389 let base_ptr = self . as_mut_ptr ( ) ;
13901390 core:: ptr:: copy ( base_ptr. add ( new_len) , base_ptr. add ( index) , 1 ) ;
1391- self . set_len ( new_len ) ;
1391+ self . len . sub ( 1 ) ;
13921392 value
13931393 }
13941394 }
@@ -1423,7 +1423,7 @@ impl<T, const N: usize> SmallVec<T, N> {
14231423 let new_len = len - 1 ;
14241424 unsafe {
14251425 // SAFETY: new_len < len
1426- self . set_len ( new_len ) ;
1426+ self . len . sub ( 1 ) ;
14271427 let ptr = self . as_mut_ptr ( ) ;
14281428 let ith = ptr. add ( index) ;
14291429 // This item is initialized since index < len
@@ -1478,7 +1478,7 @@ impl<T, const N: usize> SmallVec<T, N> {
14781478 debug_assert ! ( len < self . capacity( ) ) ;
14791479 // SAFETY: we have wrote the value to the address already
14801480 unsafe {
1481- self . len . increment ( ) ;
1481+ self . len . add ( 1 ) ;
14821482 }
14831483 }
14841484
@@ -1908,7 +1908,7 @@ impl<T: Clone, const N: usize> SmallVec<T, N> {
19081908 unsafe {
19091909 let dst = self . as_mut_ptr ( ) . add ( l) ;
19101910 copy_nonoverlapping ( src, dst, len) ;
1911- self . set_len ( l + len) ;
1911+ self . len . add ( len) ;
19121912 }
19131913 }
19141914
@@ -1932,7 +1932,7 @@ impl<T: Clone, const N: usize> SmallVec<T, N> {
19321932 let l = self . len ( ) ;
19331933 let ptr = self . as_mut_ptr ( ) ;
19341934 copy_nonoverlapping ( ptr. add ( start) , ptr. add ( l) , len) ;
1935- self . set_len ( l + len) ;
1935+ self . len . add ( len) ;
19361936 }
19371937 }
19381938
@@ -1953,7 +1953,7 @@ impl<T: Clone, const N: usize> SmallVec<T, N> {
19531953 copy_nonoverlapping ( other. as_ptr ( ) , ith_ptr, len) ;
19541954
19551955 // SAFETY: all the elements are initialized
1956- self . set_len ( l + len) ;
1956+ self . len . add ( len) ;
19571957 }
19581958 }
19591959
@@ -2238,7 +2238,7 @@ impl<T, const N: usize> SmallVec<T, N> {
22382238
22392239 // SAFETY: The elements were initialized in the loop above.
22402240 unsafe {
2241- self . set_len ( old_len + len) ;
2241+ self . len . add ( len) ;
22422242 }
22432243 }
22442244
@@ -2496,7 +2496,7 @@ unsafe impl<const N: usize> BufMut for SmallVec<u8, N> {
24962496 }
24972497
24982498 // Addition will not overflow since the sum is at most the capacity.
2499- unsafe { self . set_len ( len + cnt) } ;
2499+ unsafe { self . len . add ( cnt) } ;
25002500 }
25012501
25022502 #[ inline]
0 commit comments