diff options
| author | bors <bors@rust-lang.org> | 2013-08-26 13:41:12 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-26 13:41:12 -0700 |
| commit | 9cd91c8cc4e87f3abd9201515eefe24f0124810c (patch) | |
| tree | b3f62d87a5c3638b4f76eb11fedfc7fed89cf293 | |
| parent | ce27752a69df6093ec0d104a7ecce755983a0f78 (diff) | |
| parent | 8dc13ac3455fac12e5ad8d7ccbd043b7c31e2f9e (diff) | |
| download | rust-9cd91c8cc4e87f3abd9201515eefe24f0124810c.tar.gz rust-9cd91c8cc4e87f3abd9201515eefe24f0124810c.zip | |
auto merge of #8766 : brson/rust/vecfromfn, r=alexcrichton
A recently-enabled test of this is causing valgrind failures.
| -rw-r--r-- | src/libstd/vec.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index b743a17b472..976a3cafb32 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -75,6 +75,7 @@ use rt::global_heap::realloc_raw; use sys; use sys::size_of; use uint; +use unstable::finally::Finally; use unstable::intrinsics; use unstable::intrinsics::{get_tydesc, contains_managed}; use unstable::raw::{Box, Repr, Slice, Vec}; @@ -97,11 +98,14 @@ pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T] { let mut v = with_capacity(n_elts); let p = raw::to_mut_ptr(v); let mut i: uint = 0u; - while i < n_elts { - intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), op(i)); - i += 1u; + do (|| { + while i < n_elts { + intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), op(i)); + i += 1u; + } + }).finally { + raw::set_len(&mut v, i); } - raw::set_len(&mut v, n_elts); v } } |
