File tree 2 files changed +17
-4
lines changed
2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,15 @@ pub trait MoveMap<T> {
35
35
}
36
36
37
37
impl < T > MoveMap < T > for Vec < T > {
38
- fn move_map ( self , f: |T | -> T ) -> Vec < T > {
39
- self . move_iter ( ) . map ( f) . collect ( )
38
+ fn move_map ( mut self , f: |T | -> T ) -> Vec < T > {
39
+ use std:: { mem, ptr} ;
40
+ for p in self . mut_iter ( ) {
41
+ unsafe {
42
+ // FIXME(#5016) this shouldn't need to zero to be safe.
43
+ mem:: move_val_init ( p, f ( ptr:: read_and_zero ( p) ) ) ;
44
+ }
45
+ }
46
+ self
40
47
}
41
48
}
42
49
Original file line number Diff line number Diff line change @@ -31,8 +31,14 @@ impl<T: 'static> P<T> {
31
31
f ( * self . ptr )
32
32
}
33
33
34
- pub fn map ( self , f: |T | -> T ) -> P < T > {
35
- self . and_then ( |x| P ( f ( x) ) )
34
+ pub fn map ( mut self , f: |T | -> T ) -> P < T > {
35
+ use std:: { mem, ptr} ;
36
+ unsafe {
37
+ let p = & mut * self . ptr ;
38
+ // FIXME(#5016) this shouldn't need to zero to be safe.
39
+ mem:: move_val_init ( p, f ( ptr:: read_and_zero ( p) ) ) ;
40
+ }
41
+ self
36
42
}
37
43
}
38
44
You can’t perform that action at this time.
0 commit comments