@@ -197,14 +197,8 @@ impl<T: Clone> Vec<T> {
197
197
/// ```
198
198
#[ inline]
199
199
pub fn from_slice ( values : & [ T ] ) -> Vec < T > {
200
- let mut vector = Vec :: with_capacity ( values. len ( ) ) ;
201
-
202
- // Directly call `unsafe_push_all_clone` so we can skip a call to
203
- // `reserve_addtional`.
204
- unsafe {
205
- unsafe_push_all_clone ( & mut vector, values) ;
206
- }
207
-
200
+ let mut vector = Vec :: new ( ) ;
201
+ vector. push_all ( values) ;
208
202
vector
209
203
}
210
204
@@ -248,8 +242,18 @@ impl<T: Clone> Vec<T> {
248
242
pub fn push_all ( & mut self , other : & [ T ] ) {
249
243
self . reserve_additional ( other. len ( ) ) ;
250
244
251
- unsafe {
252
- unsafe_push_all_clone ( self , other)
245
+ for i in range ( 0 , other. len ( ) ) {
246
+ let len = self . len ( ) ;
247
+
248
+ // Unsafe code so this can be optimised to a memcpy (or something similarly
249
+ // fast) when T is Copy. LLVM is easily confused, so any extra operations
250
+ // during the loop can prevent this optimisation.
251
+ unsafe {
252
+ ptr:: write (
253
+ self . as_mut_slice ( ) . unsafe_mut_ref ( len) ,
254
+ other. unsafe_ref ( i) . clone ( ) ) ;
255
+ self . set_len ( len + 1 ) ;
256
+ }
253
257
}
254
258
}
255
259
@@ -1550,25 +1554,6 @@ pub mod raw {
1550
1554
}
1551
1555
}
1552
1556
1553
- // Unsafe code so this can be optimised to a memcpy (or something similarly
1554
- // fast) when T is Copy. LLVM is easily confused, so any extra operations
1555
- // during the loop can prevent this optimisation.
1556
- //
1557
- // WARNING: You must preallocate space on the vector before you call this
1558
- // method.
1559
- #[ inline( always) ]
1560
- unsafe fn unsafe_push_all_clone < T : Clone > ( dst : & mut Vec < T > , src : & [ T ] ) {
1561
- let mut dst_len = dst. len ( ) ;
1562
-
1563
- for i in range ( 0 , src. len ( ) ) {
1564
- ptr:: write (
1565
- dst. as_mut_slice ( ) . unsafe_mut_ref ( dst_len) ,
1566
- src. unsafe_ref ( i) . clone ( ) ) ;
1567
- dst_len += 1 ;
1568
- dst. set_len ( dst_len) ;
1569
- }
1570
- }
1571
-
1572
1557
#[ cfg( test) ]
1573
1558
mod tests {
1574
1559
extern crate test;
0 commit comments