diff options
| author | bors <bors@rust-lang.org> | 2014-05-08 21:01:42 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-08 21:01:42 -0700 |
| commit | a990920c6fff9b762c3d0968ff0a5fdcce6d2b39 (patch) | |
| tree | 8b4cb2edb2e48660ca6e6c0f6a660951f00c1e02 /src/libstd/sync | |
| parent | c0a25e4fdc1fcdde8378b4177a6f06c58001a3be (diff) | |
| parent | dc30c483810ca0ee3641f4bab8e6f2a44a883fee (diff) | |
| download | rust-a990920c6fff9b762c3d0968ff0a5fdcce6d2b39.tar.gz rust-a990920c6fff9b762c3d0968ff0a5fdcce6d2b39.zip | |
auto merge of #13963 : kballard/rust/remove_owned_vec_from_iterator, r=pcwalton
With `~[T]` no longer growable, the `FromIterator` impl for `~[T]` doesn't make much sense. Not only that, but nearly everywhere it is used is to convert from a `Vec<T>` into a `~[T]`, for the sake of maintaining existing APIs. This turns out to be a performance loss, as it means every API that returns `~[T]`, even a supposedly non-copying one, is in fact doing extra allocations and memcpy's. Even `&[T].to_owned()` is going through `Vec<T>` first. Remove the `FromIterator` impl for `~[T]`, and adjust all the APIs that relied on it to start using `Vec<T>` instead. This includes rewriting `&[T].to_owned()` to be more efficient, among other performance wins. Also add a new mechanism to go from `Vec<T>` -> `~[T]`, just in case anyone truly needs that, using the new trait `FromVec`. [breaking-change]
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/arc.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sync/deque.rs | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index d277c514e44..676c836c459 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -69,14 +69,14 @@ impl<T: Send> UnsafeArc<T> { /// As new(), but returns a vector of as many pre-cloned handles as /// requested. - pub fn newN(data: T, num_handles: uint) -> ~[UnsafeArc<T>] { + pub fn newN(data: T, num_handles: uint) -> Vec<UnsafeArc<T>> { unsafe { if num_handles == 0 { - box [] // need to free data here + vec![] // need to free data here } else { let ptr = new_inner(data, num_handles); let v = Vec::from_fn(num_handles, |_| UnsafeArc { data: ptr }); - v.move_iter().collect() + v } } } diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs index d06062f02ac..8dfd691e6ff 100644 --- a/src/libstd/sync/deque.rs +++ b/src/libstd/sync/deque.rs @@ -407,7 +407,7 @@ mod tests { use rand::Rng; use sync::atomics::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst, AtomicUint, INIT_ATOMIC_UINT}; - use slice; + use vec; #[test] fn smoke() { @@ -603,7 +603,7 @@ mod tests { let mut pool = BufferPool::<(int, uint)>::new(); let (mut w, s) = pool.deque(); - let (threads, hits) = slice::unzip(range(0, NTHREADS).map(|_| { + let (threads, hits) = vec::unzip(range(0, NTHREADS).map(|_| { let s = s.clone(); let unique_box = box AtomicUint::new(0); let thread_box = unsafe { |
