File tree 2 files changed +5
-9
lines changed
2 files changed +5
-9
lines changed Original file line number Diff line number Diff line change 62
62
#![ feature( unsafe_no_drop_flag, filling_drop) ]
63
63
#![ feature( decode_utf16) ]
64
64
#![ feature( utf8_error) ]
65
- #![ cfg_attr( test, feature( rand, test) ) ]
65
+ #![ cfg_attr( test, feature( clone_from_slice , rand, test) ) ]
66
66
67
67
#![ feature( no_std) ]
68
68
#![ no_std]
Original file line number Diff line number Diff line change @@ -1007,19 +1007,15 @@ impl<T:Clone> Clone for Vec<T> {
1007
1007
1008
1008
fn clone_from ( & mut self , other : & Vec < T > ) {
1009
1009
// drop anything in self that will not be overwritten
1010
- if self . len ( ) > other. len ( ) {
1011
- self . truncate ( other. len ( ) )
1012
- }
1010
+ self . truncate ( other. len ( ) ) ;
1011
+ let len = self . len ( ) ;
1013
1012
1014
1013
// reuse the contained values' allocations/resources.
1015
- for ( place, thing) in self . iter_mut ( ) . zip ( other) {
1016
- place. clone_from ( thing)
1017
- }
1014
+ self . clone_from_slice ( & other[ ..len] ) ;
1018
1015
1019
1016
// self.len <= other.len due to the truncate above, so the
1020
1017
// slice here is always in-bounds.
1021
- let slice = & other[ self . len ( ) ..] ;
1022
- self . push_all ( slice) ;
1018
+ self . push_all ( & other[ len..] ) ;
1023
1019
}
1024
1020
}
1025
1021
You can’t perform that action at this time.
0 commit comments