@@ -1039,18 +1039,22 @@ impl<T> Vec<T> {
1039
1039
#[ inline]
1040
1040
#[ stable( feature = "append" , since = "1.4.0" ) ]
1041
1041
pub fn append ( & mut self , other : & mut Self ) {
1042
- self . reserve ( other. len ( ) ) ;
1043
- let len = self . len ( ) ;
1044
- unsafe {
1045
- ptr:: copy_nonoverlapping ( other. as_ptr ( ) , self . get_unchecked_mut ( len) , other. len ( ) ) ;
1046
- }
1047
-
1048
- self . len += other. len ( ) ;
1049
1042
unsafe {
1043
+ self . append_elements ( other. as_slice ( ) as _ ) ;
1050
1044
other. set_len ( 0 ) ;
1051
1045
}
1052
1046
}
1053
1047
1048
+ /// Appends elements to `Self` from other buffer.
1049
+ #[ inline]
1050
+ unsafe fn append_elements ( & mut self , other : * const [ T ] ) {
1051
+ let count = ( * other) . len ( ) ;
1052
+ self . reserve ( count) ;
1053
+ let len = self . len ( ) ;
1054
+ ptr:: copy_nonoverlapping ( other as * const T , self . get_unchecked_mut ( len) , count) ;
1055
+ self . len += count;
1056
+ }
1057
+
1054
1058
/// Create a draining iterator that removes the specified range in the vector
1055
1059
/// and yields the removed items.
1056
1060
///
@@ -1681,7 +1685,7 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
1681
1685
vector
1682
1686
}
1683
1687
1684
- fn spec_extend ( & mut self , iterator : I ) {
1688
+ default fn spec_extend ( & mut self , iterator : I ) {
1685
1689
// This is the case for a TrustedLen iterator.
1686
1690
let ( low, high) = iterator. size_hint ( ) ;
1687
1691
if let Some ( high_value) = high {
@@ -1726,6 +1730,13 @@ impl<T> SpecExtend<T, IntoIter<T>> for Vec<T> {
1726
1730
vector
1727
1731
}
1728
1732
}
1733
+
1734
+ fn spec_extend ( & mut self , mut iterator : IntoIter < T > ) {
1735
+ unsafe {
1736
+ self . append_elements ( iterator. as_slice ( ) as _ ) ;
1737
+ }
1738
+ iterator. ptr = iterator. end ;
1739
+ }
1729
1740
}
1730
1741
1731
1742
impl < ' a , T : ' a , I > SpecExtend < & ' a T , I > for Vec < T >
0 commit comments