File tree Expand file tree Collapse file tree 2 files changed +4
-17
lines changed Expand file tree Collapse file tree 2 files changed +4
-17
lines changed Original file line number Diff line number Diff line change 125125#![ feature( alloc_layout_extra) ]
126126#![ feature( try_trait) ]
127127#![ feature( associated_type_bounds) ]
128+ #![ feature( slice_retain) ]
128129
129130// Allow testing this library
130131
Original file line number Diff line number Diff line change @@ -1103,26 +1103,12 @@ impl<T> Vec<T> {
11031103 /// assert_eq!(vec, [2, 3, 5]);
11041104 /// ```
11051105 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1106- pub fn retain < F > ( & mut self , mut f : F )
1106+ pub fn retain < F > ( & mut self , f : F )
11071107 where
11081108 F : FnMut ( & T ) -> bool ,
11091109 {
1110- let len = self . len ( ) ;
1111- let mut del = 0 ;
1112- {
1113- let v = & mut * * self ;
1114-
1115- for i in 0 ..len {
1116- if !f ( & v[ i] ) {
1117- del += 1 ;
1118- } else if del > 0 {
1119- v. swap ( i - del, i) ;
1120- }
1121- }
1122- }
1123- if del > 0 {
1124- self . truncate ( len - del) ;
1125- }
1110+ let retained_len = self . as_mut_slice ( ) . retain ( f) . len ( ) ;
1111+ self . truncate ( retained_len) ;
11261112 }
11271113
11281114 /// Removes all but the first of consecutive elements in the vector that resolve to the same
You can’t perform that action at this time.
0 commit comments