@@ -1212,26 +1212,7 @@ impl<T: Clone> Vec<T> {
1212
1212
/// ```
1213
1213
#[ stable( feature = "vec_extend_from_slice" , since = "1.6.0" ) ]
1214
1214
pub fn extend_from_slice ( & mut self , other : & [ T ] ) {
1215
- self . reserve ( other. len ( ) ) ;
1216
-
1217
- // Unsafe code so this can be optimised to a memcpy (or something
1218
- // similarly fast) when T is Copy. LLVM is easily confused, so any
1219
- // extra operations during the loop can prevent this optimisation.
1220
- unsafe {
1221
- let len = self . len ( ) ;
1222
- let ptr = self . get_unchecked_mut ( len) as * mut T ;
1223
- // Use SetLenOnDrop to work around bug where compiler
1224
- // may not realize the store through `ptr` trough self.set_len()
1225
- // don't alias.
1226
- let mut local_len = SetLenOnDrop :: new ( & mut self . len ) ;
1227
-
1228
- for i in 0 ..other. len ( ) {
1229
- ptr:: write ( ptr. offset ( i as isize ) , other. get_unchecked ( i) . clone ( ) ) ;
1230
- local_len. increment_len ( 1 ) ;
1231
- }
1232
-
1233
- // len set by scope guard
1234
- }
1215
+ self . extend ( other. iter ( ) . cloned ( ) )
1235
1216
}
1236
1217
}
1237
1218
@@ -1640,24 +1621,7 @@ impl<T> Vec<T> {
1640
1621
#[ stable( feature = "extend_ref" , since = "1.2.0" ) ]
1641
1622
impl < ' a , T : ' a + Copy > Extend < & ' a T > for Vec < T > {
1642
1623
fn extend < I : IntoIterator < Item = & ' a T > > ( & mut self , iter : I ) {
1643
- <I as SpecExtendVec < T > >:: extend_vec ( iter, self ) ;
1644
- }
1645
- }
1646
-
1647
- // helper trait for specialization of Vec's Extend impl
1648
- trait SpecExtendVec < T > {
1649
- fn extend_vec ( self , vec : & mut Vec < T > ) ;
1650
- }
1651
-
1652
- impl < ' a , T : ' a + Copy , I : IntoIterator < Item =& ' a T > > SpecExtendVec < T > for I {
1653
- default fn extend_vec ( self , vec : & mut Vec < T > ) {
1654
- vec. extend ( self . into_iter ( ) . cloned ( ) ) ;
1655
- }
1656
- }
1657
-
1658
- impl < ' a , T : Copy > SpecExtendVec < T > for & ' a [ T ] {
1659
- fn extend_vec ( self , vec : & mut Vec < T > ) {
1660
- vec. extend_from_slice ( self ) ;
1624
+ self . extend ( iter. into_iter ( ) . map ( |& x| x) )
1661
1625
}
1662
1626
}
1663
1627
0 commit comments