File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ use rt::global_heap::realloc_raw;
75
75
use sys;
76
76
use sys:: size_of;
77
77
use uint;
78
+ use unstable:: finally:: Finally ;
78
79
use unstable:: intrinsics;
79
80
use unstable:: intrinsics:: { get_tydesc, contains_managed} ;
80
81
use unstable:: raw:: { Box , Repr , Slice , Vec } ;
@@ -97,11 +98,14 @@ pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T] {
97
98
let mut v = with_capacity ( n_elts) ;
98
99
let p = raw:: to_mut_ptr ( v) ;
99
100
let mut i: uint = 0 u;
100
- while i < n_elts {
101
- intrinsics:: move_val_init ( & mut ( * ptr:: mut_offset ( p, i as int ) ) , op ( i) ) ;
102
- i += 1 u;
101
+ do ( || {
102
+ while i < n_elts {
103
+ intrinsics:: move_val_init ( & mut ( * ptr:: mut_offset ( p, i as int ) ) , op ( i) ) ;
104
+ i += 1 u;
105
+ }
106
+ } ) . finally {
107
+ raw:: set_len ( & mut v, i) ;
103
108
}
104
- raw:: set_len ( & mut v, n_elts) ;
105
109
v
106
110
}
107
111
}
You can’t perform that action at this time.
0 commit comments