File tree 2 files changed +4
-17
lines changed
2 files changed +4
-17
lines changed Original file line number Diff line number Diff line change 125
125
#![ feature( alloc_layout_extra) ]
126
126
#![ feature( try_trait) ]
127
127
#![ feature( associated_type_bounds) ]
128
+ #![ feature( slice_retain) ]
128
129
129
130
// Allow testing this library
130
131
Original file line number Diff line number Diff line change @@ -1103,26 +1103,12 @@ impl<T> Vec<T> {
1103
1103
/// assert_eq!(vec, [2, 3, 5]);
1104
1104
/// ```
1105
1105
#[ 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 )
1107
1107
where
1108
1108
F : FnMut ( & T ) -> bool ,
1109
1109
{
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) ;
1126
1112
}
1127
1113
1128
1114
/// 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