File tree Expand file tree Collapse file tree 2 files changed +5
-9
lines changed Expand file tree Collapse file tree 2 files changed +5
-9
lines changed Original file line number Diff line number Diff line change 6262#![ feature( unsafe_no_drop_flag, filling_drop) ]
6363#![ feature( decode_utf16) ]
6464#![ feature( utf8_error) ]
65- #![ cfg_attr( test, feature( rand, test) ) ]
65+ #![ cfg_attr( test, feature( clone_from_slice , rand, test) ) ]
6666
6767#![ feature( no_std) ]
6868#![ no_std]
Original file line number Diff line number Diff line change @@ -1007,19 +1007,15 @@ impl<T:Clone> Clone for Vec<T> {
10071007
10081008 fn clone_from ( & mut self , other : & Vec < T > ) {
10091009 // 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 ( ) ;
10131012
10141013 // 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] ) ;
10181015
10191016 // self.len <= other.len due to the truncate above, so the
10201017 // slice here is always in-bounds.
1021- let slice = & other[ self . len ( ) ..] ;
1022- self . push_all ( slice) ;
1018+ self . push_all ( & other[ len..] ) ;
10231019 }
10241020}
10251021
You can’t perform that action at this time.
0 commit comments