Skip to content

Commit 9cd91c8

Browse files
committed
auto merge of #8766 : brson/rust/vecfromfn, r=alexcrichton
A recently-enabled test of this is causing valgrind failures.
2 parents ce27752 + 8dc13ac commit 9cd91c8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/libstd/vec.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use rt::global_heap::realloc_raw;
7575
use sys;
7676
use sys::size_of;
7777
use uint;
78+
use unstable::finally::Finally;
7879
use unstable::intrinsics;
7980
use unstable::intrinsics::{get_tydesc, contains_managed};
8081
use unstable::raw::{Box, Repr, Slice, Vec};
@@ -97,11 +98,14 @@ pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T] {
9798
let mut v = with_capacity(n_elts);
9899
let p = raw::to_mut_ptr(v);
99100
let mut i: uint = 0u;
100-
while i < n_elts {
101-
intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), op(i));
102-
i += 1u;
101+
do (|| {
102+
while i < n_elts {
103+
intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), op(i));
104+
i += 1u;
105+
}
106+
}).finally {
107+
raw::set_len(&mut v, i);
103108
}
104-
raw::set_len(&mut v, n_elts);
105109
v
106110
}
107111
}

0 commit comments

Comments
 (0)