@@ -796,15 +796,14 @@ impl<A: Array> SmallVec<A> {
796
796
// so that the optimizer removes duplicated calls to it
797
797
// from callers like insert()
798
798
let ( _, & mut len, cap) = self . triple_mut ( ) ;
799
- if cap - len < additional {
800
- let new_cap = len
801
- . checked_add ( additional)
802
- . and_then ( usize:: checked_next_power_of_two)
803
- . ok_or ( CollectionAllocErr :: CapacityOverflow ) ?;
804
- self . try_grow ( new_cap)
805
- } else {
806
- Ok ( ( ) )
799
+ if cap - len >= additional {
800
+ return Ok ( ( ) ) ;
807
801
}
802
+ let new_cap = len
803
+ . checked_add ( additional)
804
+ . and_then ( usize:: checked_next_power_of_two)
805
+ . ok_or ( CollectionAllocErr :: CapacityOverflow ) ?;
806
+ self . try_grow ( new_cap)
808
807
}
809
808
810
809
/// Reserve the minimum capacity for `additional` more elements to be inserted.
@@ -817,14 +816,13 @@ impl<A: Array> SmallVec<A> {
817
816
/// Reserve the minimum capacity for `additional` more elements to be inserted.
818
817
pub fn try_reserve_exact ( & mut self , additional : usize ) -> Result < ( ) , CollectionAllocErr > {
819
818
let ( _, & mut len, cap) = self . triple_mut ( ) ;
820
- if cap - len < additional {
821
- let new_cap = len
822
- . checked_add ( additional)
823
- . ok_or ( CollectionAllocErr :: CapacityOverflow ) ?;
824
- self . try_grow ( new_cap)
825
- } else {
826
- Ok ( ( ) )
819
+ if cap - len >= additional {
820
+ return Ok ( ( ) ) ;
827
821
}
822
+ let new_cap = len
823
+ . checked_add ( additional)
824
+ . ok_or ( CollectionAllocErr :: CapacityOverflow ) ?;
825
+ self . try_grow ( new_cap)
828
826
}
829
827
830
828
/// Shrink the capacity of the vector as much as possible.
0 commit comments