diff options
| author | bors <bors@rust-lang.org> | 2014-02-01 11:16:24 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-01 11:16:24 -0800 |
| commit | 2bcd951749b67402ccaa31f1bb0349656f880fe2 (patch) | |
| tree | bb3de89383f032ca622a27e20e237282c9569a48 /src/libstd | |
| parent | 60ffbeb2a495d097e38f51348ebcf5a884947c25 (diff) | |
| parent | 212507413a2768ec4b6a072dde73d60527c2beee (diff) | |
| download | rust-2bcd951749b67402ccaa31f1bb0349656f880fe2.tar.gz rust-2bcd951749b67402ccaa31f1bb0349656f880fe2.zip | |
auto merge of #11974 : huonw/rust/no-at-vec, r=pcwalton
This removes @[] from the parser as well as much of the handling of it (and `@str`) from the compiler as I can find. I've just rebased @pcwalton's (already reviewed) `@str` removal (and fixed the problems in a separate commit); the only new work is the trailing commits with my authorship. Closes #11967
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/at_vec.rs | 424 | ||||
| -rw-r--r-- | src/libstd/fmt/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/gc.rs | 1 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/path/mod.rs | 20 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 10 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 10 | ||||
| -rw-r--r-- | src/libstd/reflect.rs | 8 | ||||
| -rw-r--r-- | src/libstd/repr.rs | 12 | ||||
| -rw-r--r-- | src/libstd/rt/local_heap.rs | 2 | ||||
| -rw-r--r-- | src/libstd/send_str.rs | 2 | ||||
| -rw-r--r-- | src/libstd/str.rs | 131 | ||||
| -rw-r--r-- | src/libstd/to_bytes.rs | 14 | ||||
| -rw-r--r-- | src/libstd/to_str.rs | 20 | ||||
| -rw-r--r-- | src/libstd/unstable/raw.rs | 2 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 60 |
16 files changed, 14 insertions, 704 deletions
diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs deleted file mode 100644 index 55e90248e1c..00000000000 --- a/src/libstd/at_vec.rs +++ /dev/null @@ -1,424 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Operations on managed vectors (`@[T]` type) - -use clone::Clone; -use container::Container; -use iter::{Iterator, FromIterator}; -use option::{Option, Some, None}; -use mem; -use unstable::raw::Repr; -use vec::{ImmutableVector, OwnedVector}; - -/// Code for dealing with @-vectors. This is pretty incomplete, and -/// contains a bunch of duplication from the code for ~-vectors. - -/// Returns the number of elements the vector can hold without reallocating -#[inline] -pub fn capacity<T>(v: @[T]) -> uint { - unsafe { - let managed_box = v.repr(); - (*managed_box).data.alloc / mem::size_of::<T>() - } -} - -/** - * Builds a vector by calling a provided function with an argument - * function that pushes an element to the back of a vector. - * The initial size for the vector may optionally be specified - * - * # Arguments - * - * * size - An option, maybe containing initial size of the vector to reserve - * * builder - A function that will construct the vector. It receives - * as an argument a function that will push an element - * onto the vector being constructed. - */ -#[inline] -pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> @[A] { - let mut vec = @[]; - unsafe { raw::reserve(&mut vec, size.unwrap_or(4)); } - builder(|x| unsafe { raw::push(&mut vec, x) }); - vec -} - -// Appending - -/// Iterates over the `rhs` vector, copying each element and appending it to the -/// `lhs`. Afterwards, the `lhs` is then returned for use again. -#[inline] -pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] { - build(Some(lhs.len() + rhs.len()), |push| { - for x in lhs.iter() { - push((*x).clone()); - } - for elt in rhs.iter() { - push(elt.clone()); - } - }) -} - - -/// Apply a function to each element of a vector and return the results -#[inline] -pub fn map<T, U>(v: &[T], f: |x: &T| -> U) -> @[U] { - build(Some(v.len()), |push| { - for elem in v.iter() { - push(f(elem)); - } - }) -} - -/** - * Creates and initializes an immutable vector. - * - * Creates an immutable vector of size `n_elts` and initializes the elements - * to the value returned by the function `op`. - */ -#[inline] -pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> @[T] { - build(Some(n_elts), |push| { - let mut i: uint = 0u; - while i < n_elts { push(op(i)); i += 1u; } - }) -} - -/** - * Creates and initializes an immutable vector. - * - * Creates an immutable vector of size `n_elts` and initializes the elements - * to the value `t`. - */ -#[inline] -pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> @[T] { - build(Some(n_elts), |push| { - let mut i: uint = 0u; - while i < n_elts { - push(t.clone()); - i += 1u; - } - }) -} - -/** - * Creates and initializes an immutable managed vector by moving all the - * elements from an owned vector. - */ -#[inline] -pub fn to_managed_move<T>(v: ~[T]) -> @[T] { - let mut av = @[]; - unsafe { - raw::reserve(&mut av, v.len()); - for x in v.move_iter() { - raw::push(&mut av, x); - } - av - } -} - -/** - * Creates and initializes an immutable managed vector by copying all the - * elements of a slice. - */ -#[inline] -pub fn to_managed<T:Clone>(v: &[T]) -> @[T] { - from_fn(v.len(), |i| v[i].clone()) -} - -impl<T> Clone for @[T] { - fn clone(&self) -> @[T] { - *self - } -} - -impl<A> FromIterator<A> for @[A] { - #[inline] - fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> @[A] { - let (lower, _) = iterator.size_hint(); - build(Some(lower), |push| { - for x in *iterator { - push(x); - } - }) - } -} - -#[cfg(not(test))] -#[allow(missing_doc)] -pub mod traits { - use at_vec::append; - use clone::Clone; - use ops::Add; - use vec::Vector; - - impl<'a,T:Clone, V: Vector<T>> Add<V,@[T]> for @[T] { - #[inline] - fn add(&self, rhs: &V) -> @[T] { - append(*self, rhs.as_slice()) - } - } -} - -#[cfg(test)] -pub mod traits {} - -#[allow(missing_doc)] -pub mod raw { - use at_vec::capacity; - use cast; - use cast::{transmute, transmute_copy}; - use container::Container; - use option::None; - use mem; - use num::next_power_of_two; - use ptr; - use unstable::intrinsics::{move_val_init, TyDesc}; - use unstable::intrinsics; - use unstable::raw::{Box, Vec}; - - /** - * Sets the length of a vector - * - * This will explicitly set the size of the vector, without actually - * modifying its buffers, so it is up to the caller to ensure that - * the vector is actually the specified size. - */ - #[inline] - pub unsafe fn set_len<T>(v: &mut @[T], new_len: uint) { - let repr: *mut Box<Vec<T>> = cast::transmute_copy(v); - (*repr).data.fill = new_len * mem::size_of::<T>(); - } - - /** - * Pushes a new value onto this vector. - */ - #[inline] - pub unsafe fn push<T>(v: &mut @[T], initval: T) { - let full = { - let repr: *Box<Vec<T>> = cast::transmute_copy(v); - (*repr).data.alloc > (*repr).data.fill - }; - if full { - push_fast(v, initval); - } else { - push_slow(v, initval); - } - } - - #[inline] // really pretty please - unsafe fn push_fast<T>(v: &mut @[T], initval: T) { - let repr: *mut Box<Vec<T>> = cast::transmute_copy(v); - let amt = v.len(); - (*repr).data.fill += mem::size_of::<T>(); - let p = ptr::offset(&(*repr).data.data as *T, amt as int) as *mut T; - move_val_init(&mut(*p), initval); - } - - #[inline] - unsafe fn push_slow<T>(v: &mut @[T], initval: T) { - reserve_at_least(v, v.len() + 1u); - push_fast(v, initval); - } - - /** - * Reserves capacity for exactly `n` elements in the given vector. - * - * If the capacity for `v` is already equal to or greater than the - * requested capacity, then no action is taken. - * - * # Arguments - * - * * v - A vector - * * n - The number of elements to reserve space for - */ - #[inline] - pub unsafe fn reserve<T>(v: &mut @[T], n: uint) { - // Only make the (slow) call into the runtime if we have to - if capacity(*v) < n { - let ptr: *mut *mut Box<Vec<()>> = transmute(v); - let ty = intrinsics::get_tydesc::<T>(); - return reserve_raw(ty, ptr, n); - } - } - - // Implementation detail. Shouldn't be public - #[allow(missing_doc)] - #[inline] - pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box<Vec<()>>, n: uint) { - // check for `uint` overflow - unsafe { - if n > (**ptr).data.alloc / (*ty).size { - let alloc = n * (*ty).size; - let total_size = alloc + mem::size_of::<Vec<()>>(); - if alloc / (*ty).size != n || total_size < alloc { - fail!("vector size is too large: {}", n); - } - (*ptr) = local_realloc(*ptr as *(), total_size) as *mut Box<Vec<()>>; - (**ptr).data.alloc = alloc; - } - } - - #[inline] - fn local_realloc(ptr: *(), size: uint) -> *() { - use rt::local::Local; - use rt::task::Task; - - let mut task = Local::borrow(None::<Task>); - task.get().heap.realloc(ptr as *mut Box<()>, size) as *() - } - } - - /** - * Reserves capacity for at least `n` elements in the given vector. - * - * This function will over-allocate in order to amortize the - * allocation costs in scenarios where the caller may need to - * repeatedly reserve additional space. - * - * If the capacity for `v` is already equal to or greater than the - * requested capacity, then no action is taken. - * - * # Arguments - * - * * v - A vector - * * n - The number of elements to reserve space for - */ - #[inline] - pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) { - reserve(v, next_power_of_two(n)); - } -} - -#[cfg(test)] -mod test { - use super::*; - use prelude::*; - use bh = extra::test::BenchHarness; - - #[test] - fn test() { - // Some code that could use that, then: - fn seq_range(lo: uint, hi: uint) -> @[uint] { - build(None, |push| { - for i in range(lo, hi) { - push(i); - } - }) - } - - assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]); - assert_eq!(from_fn(5, |x| x+1), @[1, 2, 3, 4, 5]); - assert_eq!(from_elem(5, 3.14), @[3.14, 3.14, 3.14, 3.14, 3.14]); - } - - #[test] - fn append_test() { - assert_eq!(@[1,2,3] + &[4,5,6], @[1,2,3,4,5,6]); - } - - #[test] - fn test_to_managed_move() { - assert_eq!(to_managed_move::<int>(~[]), @[]); - assert_eq!(to_managed_move(~[true]), @[true]); - assert_eq!(to_managed_move(~[1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]); - assert_eq!(to_managed_move(~[~"abc", ~"123"]), @[~"abc", ~"123"]); - assert_eq!(to_managed_move(~[~[42]]), @[~[42]]); - } - - #[test] - fn test_to_managed() { - assert_eq!(to_managed::<int>([]), @[]); - assert_eq!(to_managed([true]), @[true]); - assert_eq!(to_managed([1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]); - assert_eq!(to_managed([@"abc", @"123"]), @[@"abc", @"123"]); - assert_eq!(to_managed([@[42]]), @[@[42]]); - } - - #[bench] - fn bench_capacity(b: &mut bh) { - let x = @[1, 2, 3]; - b.iter(|| { - let _ = capacity(x); - }); - } - - #[bench] - fn bench_build_sized(b: &mut bh) { - let len = 64; - b.iter(|| { - build(Some(len), |push| for i in range(0, 1024) { push(i) }); - }); - } - - #[bench] - fn bench_build(b: &mut bh) { - b.iter(|| { - for i in range(0, 95) { - build(None, |push| push(i)); - } - }); - } - - #[bench] - fn bench_append(b: &mut bh) { - let lhs = @[7, ..128]; - let rhs = range(0, 256).to_owned_vec(); - b.iter(|| { - let _ = append(lhs, rhs); - }) - } - - #[bench] - fn bench_map(b: &mut bh) { - let elts = range(0, 256).to_owned_vec(); - b.iter(|| { - let _ = map(elts, |x| x*2); - }) - } - - #[bench] - fn bench_from_fn(b: &mut bh) { - b.iter(|| { - let _ = from_fn(1024, |x| x); - }); - } - - #[bench] - fn bench_from_elem(b: &mut bh) { - b.iter(|| { - let _ = from_elem(1024, 0u64); - }); - } - - #[bench] - fn bench_to_managed_move(b: &mut bh) { - b.iter(|| { - let elts = range(0, 1024).to_owned_vec(); // yikes! can't move out of capture, though - to_managed_move(elts); - }) - } - - #[bench] - fn bench_to_managed(b: &mut bh) { - let elts = range(0, 1024).to_owned_vec(); - b.iter(|| { - let _ = to_managed(elts); - }); - } - - #[bench] - fn bench_clone(b: &mut bh) { - let elts = to_managed(range(0, 1024).to_owned_vec()); - b.iter(|| { - let _ = elts.clone(); - }); - } -} diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 111eb70eb20..13e6d808095 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -1167,7 +1167,6 @@ delegate!( u8 to Unsigned) delegate!( u16 to Unsigned) delegate!( u32 to Unsigned) delegate!( u64 to Unsigned) -delegate!(@str to String) delegate!(~str to String) delegate!(&'a str to String) delegate!(bool to Bool) diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 8ec07290a31..fa7c94ac994 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -35,7 +35,6 @@ pub struct Gc<T> { } #[cfg(test)] -#[no_send] pub struct Gc<T> { priv ptr: @T, priv marker: marker::NoSend, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d7a7011319a..adce11fed2d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -114,7 +114,6 @@ pub mod tuple; pub mod vec; pub mod vec_ng; -pub mod at_vec; pub mod str; pub mod ascii; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 11f23b22c51..c5482811a94 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -604,19 +604,6 @@ impl BytesContainer for ~str { fn is_str(_: Option<~str>) -> bool { true } } -impl BytesContainer for @str { - #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { - self.as_bytes() - } - #[inline] - fn container_as_str<'a>(&'a self) -> Option<&'a str> { - Some(self.as_slice()) - } - #[inline] - fn is_str(_: Option<@str>) -> bool { true } -} - impl<'a> BytesContainer for &'a [u8] { #[inline] fn container_as_bytes<'a>(&'a self) -> &'a [u8] { @@ -635,13 +622,6 @@ impl BytesContainer for ~[u8] { } } -impl BytesContainer for @[u8] { - #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { - self.as_slice() - } -} - impl BytesContainer for CString { #[inline] fn container_as_bytes<'a>(&'a self) -> &'a [u8] { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 707ba18378a..ba0cd0bb521 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -807,8 +807,6 @@ mod tests { #[test] fn test_push_many() { - use to_man = at_vec::to_managed_move; - macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { @@ -830,12 +828,9 @@ mod tests { t!(s: "a/b/c", ["d", "/e"], "/e"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); - t!(s: "a/b/c", [@"d", @"e"], "a/b/c/d/e"); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d"), b!("/e"), b!("f")], b!("/e/f")); t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e")); - t!(v: b!("a/b/c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], - b!("a/b/c/d/e")); } #[test] @@ -917,8 +912,6 @@ mod tests { #[test] fn test_join_many() { - use to_man = at_vec::to_managed_move; - macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { @@ -940,11 +933,8 @@ mod tests { t!(s: "a/b/c", ["..", "d"], "a/b/d"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); - t!(s: "a/b/c", [@"d", @"e"], "a/b/c/d/e"); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e")); - t!(v: b!("a/b/c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], - b!("a/b/c/d/e")); } #[test] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index a07471afc1a..eec6f37b627 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1587,8 +1587,6 @@ mod tests { #[test] fn test_push_many() { - use to_man = at_vec::to_managed_move; - macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { @@ -1610,12 +1608,9 @@ mod tests { t!(s: "a\\b\\c", ["d", "\\e"], "\\e"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); - t!(s: "a\\b\\c", [@"d", @"e"], "a\\b\\c\\d\\e"); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d"), b!("\\e"), b!("f")], b!("\\e\\f")); t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e")); - t!(v: b!("a\\b\\c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], - b!("a\\b\\c\\d\\e")); } #[test] @@ -1732,8 +1727,6 @@ mod tests { #[test] fn test_join_many() { - use to_man = at_vec::to_managed_move; - macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { @@ -1755,11 +1748,8 @@ mod tests { t!(s: "a\\b\\c", ["..", "d"], "a\\b\\d"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); - t!(s: "a\\b\\c", [@"d", @"e"], "a\\b\\c\\d\\e"); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e")); - t!(v: b!("a\\b\\c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], - b!("a\\b\\c\\d\\e")); } #[test] diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index 87655f5911f..d6b4d3f5656 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -183,9 +183,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { } fn visit_estr_box(&mut self) -> bool { - self.align_to::<@str>(); - if ! self.inner.visit_estr_box() { return false; } - self.bump_past::<@str>(); true } @@ -253,10 +250,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { true } - fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<@[u8]>(); - if ! self.inner.visit_evec_box(mtbl, inner) { return false; } - self.bump_past::<@[u8]>(); + fn visit_evec_box(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { true } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 1ecc31ec2f4..41ddf027787 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -272,10 +272,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { } fn visit_estr_box(&mut self) -> bool { - self.get::<@str>(|this, s| { - this.writer.write(['@' as u8]); - this.write_escaped_slice(*s); - }) + true } fn visit_estr_uniq(&mut self) -> bool { @@ -628,7 +625,6 @@ fn test_repr() { exact_test(&false, "false"); exact_test(&1.234, "1.234f64"); exact_test(&(&"hello"), "\"hello\""); - exact_test(&(@"hello"), "@\"hello\""); exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\""); exact_test(&(@10), "@10"); @@ -641,12 +637,6 @@ fn test_repr() { exact_test(&(0 as *mut ()), "(0x0 as *mut ())"); exact_test(&(1,), "(1,)"); - exact_test(&(@[1,2,3,4,5,6,7,8]), - "@[1, 2, 3, 4, 5, 6, 7, 8]"); - exact_test(&(@[1u8,2u8,3u8,4u8]), - "@[1u8, 2u8, 3u8, 4u8]"); - exact_test(&(@["hi", "there"]), - "@[\"hi\", \"there\"]"); exact_test(&(~["hi", "there"]), "~[\"hi\", \"there\"]"); exact_test(&(&["hi", "there"]), diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index 42a7e7867f9..79936b4afad 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -332,6 +332,6 @@ mod bench { #[bench] fn alloc_managed_big(bh: &mut BenchHarness) { - bh.iter(|| { @[10, ..1000]; }); + bh.iter(|| { @([10, ..1000]); }); } } diff --git a/src/libstd/send_str.rs b/src/libstd/send_str.rs index 2599a74a748..b075b75b70a 100644 --- a/src/libstd/send_str.rs +++ b/src/libstd/send_str.rs @@ -185,7 +185,6 @@ mod tests { assert_eq!(s.len(), 5); assert_eq!(s.as_slice(), "abcde"); assert_eq!(s.to_str(), ~"abcde"); - assert!(s.equiv(&@"abcde")); assert!(s.lt(&SendStrOwned(~"bcdef"))); assert_eq!(SendStrStatic(""), Default::default()); @@ -193,7 +192,6 @@ mod tests { assert_eq!(o.len(), 5); assert_eq!(o.as_slice(), "abcde"); assert_eq!(o.to_str(), ~"abcde"); - assert!(o.equiv(&@"abcde")); assert!(o.lt(&SendStrStatic("bcdef"))); assert_eq!(SendStrOwned(~""), Default::default()); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 3cc199ce195..0315e560bb7 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -17,46 +17,35 @@ Unicode string manipulation (`str` type) Rust's string type is one of the core primitive types of the language. While represented by the name `str`, the name `str` is not actually a valid type in Rust. Each string must also be decorated with its ownership. This means that -there are three common kinds of strings in rust: +there are two common kinds of strings in rust: * `~str` - This is an owned string. This type obeys all of the normal semantics of the `~T` types, meaning that it has one, and only one, owner. This type cannot be implicitly copied, and is moved out of when passed to other functions. -* `@str` - This is a managed string. Similarly to `@T`, this type can be - implicitly copied, and each implicit copy will increment the - reference count to the string. This means that there is no "true - owner" of the string, and the string will be deallocated when the - reference count reaches 0. - -* `&str` - Finally, this is the borrowed string type. This type of string can - only be created from one of the other two kinds of strings. As the - name "borrowed" implies, this type of string is owned elsewhere, and - this string cannot be moved out of. +* `&str` - This is the borrowed string type. This type of string can only be + created from the other kind of string. As the name "borrowed" + implies, this type of string is owned elsewhere, and this string + cannot be moved out of. As an example, here's a few different kinds of strings. ```rust -#[feature(managed_boxes)]; - fn main() { let owned_string = ~"I am an owned string"; - let managed_string = @"This string is garbage-collected"; let borrowed_string1 = "This string is borrowed with the 'static lifetime"; let borrowed_string2: &str = owned_string; // owned strings can be borrowed - let borrowed_string3: &str = managed_string; // managed strings can also be borrowed } ``` -From the example above, you can see that rust has 3 different kinds of string -literals. The owned/managed literals correspond to the owned/managed string -types, but the "borrowed literal" is actually more akin to C's concept of a -static string. +From the example above, you can see that rust has 2 different kinds of string +literals. The owned literals correspond to the owned string types, but the +"borrowed literal" is actually more akin to C's concept of a static string. -When a string is declared without a `~` or `@` sigil, then the string is -allocated statically in the rodata of the executable/library. The string then -has the type `&'static str` meaning that the string is valid for the `'static` +When a string is declared without a `~` sigil, then the string is allocated +statically in the rodata of the executable/library. The string then has the +type `&'static str` meaning that the string is valid for the `'static` lifetime, otherwise known as the lifetime of the entire program. As can be inferred from the type, these static strings are not mutable. @@ -89,11 +78,9 @@ The actual representation of strings have direct mappings to vectors: * `~str` is the same as `~[u8]` * `&str` is the same as `&[u8]` -* `@str` is the same as `@[u8]` */ -use at_vec; use cast; use cast::transmute; use char; @@ -157,16 +144,6 @@ impl<'a> ToStr for &'a str { fn to_str(&self) -> ~str { self.to_owned() } } -impl ToStr for @str { - #[inline] - fn to_str(&self) -> ~str { self.to_owned() } -} - -impl<'a> FromStr for @str { - #[inline] - fn from_str(s: &str) -> Option<@str> { Some(s.to_managed()) } -} - /// Convert a byte to a UTF-8 string /// /// # Failure @@ -1140,11 +1117,6 @@ pub mod traits { fn cmp(&self, other: &~str) -> Ordering { self.as_slice().cmp(&other.as_slice()) } } - impl TotalOrd for @str { - #[inline] - fn cmp(&self, other: &@str) -> Ordering { self.as_slice().cmp(&other.as_slice()) } - } - impl<'a> Eq for &'a str { #[inline] fn eq(&self, other: & &'a str) -> bool { @@ -1161,13 +1133,6 @@ pub mod traits { } } - impl Eq for @str { - #[inline] - fn eq(&self, other: &@str) -> bool { - eq_slice((*self), (*other)) - } - } - impl<'a> TotalEq for &'a str { #[inline] fn equals(&self, other: & &'a str) -> bool { @@ -1182,13 +1147,6 @@ pub mod traits { } } - impl TotalEq for @str { - #[inline] - fn equals(&self, other: &@str) -> bool { - eq_slice((*self), (*other)) - } - } - impl<'a> Ord for &'a str { #[inline] fn lt(&self, other: & &'a str) -> bool { self.cmp(other) == Less } @@ -1199,21 +1157,11 @@ pub mod traits { fn lt(&self, other: &~str) -> bool { self.cmp(other) == Less } } - impl Ord for @str { - #[inline] - fn lt(&self, other: &@str) -> bool { self.cmp(other) == Less } - } - impl<'a, S: Str> Equiv<S> for &'a str { #[inline] fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } } - impl<'a, S: Str> Equiv<S> for @str { - #[inline] - fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } - } - impl<'a, S: Str> Equiv<S> for ~str { #[inline] fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } @@ -1250,16 +1198,6 @@ impl<'a> Str for ~str { fn into_owned(self) -> ~str { self } } -impl<'a> Str for @str { - #[inline] - fn as_slice<'a>(&'a self) -> &'a str { - let s: &'a str = *self; s - } - - #[inline] - fn into_owned(self) -> ~str { self.to_owned() } -} - impl<'a> Container for &'a str { #[inline] fn len(&self) -> uint { @@ -1272,11 +1210,6 @@ impl Container for ~str { fn len(&self) -> uint { self.as_slice().len() } } -impl Container for @str { - #[inline] - fn len(&self) -> uint { self.as_slice().len() } -} - impl Mutable for ~str { /// Remove all content, make the string empty #[inline] @@ -1734,9 +1667,6 @@ pub trait StrSlice<'a> { /// Copy a slice into a new owned str. fn to_owned(&self) -> ~str; - /// Copy a slice into a new managed str. - fn to_managed(&self) -> @str; - /// Converts to a vector of `u16` encoded as UTF-16. fn to_utf16(&self) -> ~[u16]; @@ -2246,14 +2176,6 @@ impl<'a> StrSlice<'a> for &'a str { } } - #[inline] - fn to_managed(&self) -> @str { - unsafe { - let v: *&[u8] = cast::transmute(self); - cast::transmute(at_vec::to_managed(*v)) - } - } - fn to_utf16(&self) -> ~[u16] { let mut u = ~[]; for ch in self.chars() { @@ -2682,20 +2604,6 @@ impl DeepClone for ~str { } } -impl Clone for @str { - #[inline] - fn clone(&self) -> @str { - *self - } -} - -impl DeepClone for @str { - #[inline] - fn deep_clone(&self) -> @str { - *self - } -} - impl FromIterator<char> for ~str { #[inline] fn from_iterator<T: Iterator<char>>(iterator: &mut T) -> ~str { @@ -2727,10 +2635,6 @@ impl Default for ~str { fn default() -> ~str { ~"" } } -impl Default for @str { - fn default() -> @str { @"" } -} - #[cfg(test)] mod tests { use iter::AdditiveIterator; @@ -3537,12 +3441,6 @@ mod tests { } #[test] - fn test_to_managed() { - assert_eq!("abc".to_managed(), @"abc"); - assert_eq!("abcdef".slice(1, 5).to_managed(), @"bcde"); - } - - #[test] fn test_total_ord() { "1234".cmp(& &"123") == Greater; "123".cmp(& &"1234") == Less; @@ -3579,15 +3477,12 @@ mod tests { let e = $e; assert_eq!(s1 + s2, e.to_owned()); assert_eq!(s1.to_owned() + s2, e.to_owned()); - assert_eq!(s1.to_managed() + s2, e.to_owned()); } } ); t!("foo", "bar", "foobar"); - t!("foo", @"bar", "foobar"); t!("foo", ~"bar", "foobar"); t!("ศไทย中", "华Việt Nam", "ศไทย中华Việt Nam"); - t!("ศไทย中", @"华Việt Nam", "ศไทย中华Việt Nam"); t!("ศไทย中", ~"华Việt Nam", "ศไทย中华Việt Nam"); } @@ -3874,7 +3769,6 @@ mod tests { } t::<&str>(); - t::<@str>(); t::<~str>(); } @@ -3886,7 +3780,6 @@ mod tests { let s = ~"01234"; assert_eq!(5, sum_len(["012", "", "34"])); - assert_eq!(5, sum_len([@"01", @"2", @"34", @""])); assert_eq!(5, sum_len([~"01", ~"2", ~"34", ~""])); assert_eq!(5, sum_len([s.as_slice()])); } @@ -3957,8 +3850,6 @@ mod tests { fn test_from_str() { let owned: Option<~str> = from_str(&"string"); assert_eq!(owned, Some(~"string")); - let managed: Option<@str> = from_str(&"string"); - assert_eq!(managed, Some(@"string")); } } diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 8df028f56d5..4c545de73b4 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -266,13 +266,6 @@ impl<A:IterBytes> IterBytes for ~[A] { } } -impl<A:IterBytes> IterBytes for @[A] { - #[inline] - fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { - self.as_slice().iter_bytes(lsb0, f) - } -} - impl<'a> IterBytes for &'a str { #[inline] fn iter_bytes(&self, _lsb0: bool, f: Cb) -> bool { @@ -288,13 +281,6 @@ impl IterBytes for ~str { } } -impl IterBytes for @str { - #[inline] - fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { - self.as_slice().iter_bytes(lsb0, f) - } -} - impl<A:IterBytes> IterBytes for Option<A> { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index a58b09d8ecd..87d59f09791 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -159,25 +159,6 @@ impl<A:ToStr> ToStr for ~[A] { } } -impl<A:ToStr> ToStr for @[A] { - #[inline] - fn to_str(&self) -> ~str { - let mut acc = ~"["; - let mut first = true; - for elt in self.iter() { - if first { - first = false; - } - else { - acc.push_str(", "); - } - acc.push_str(elt.to_str()); - } - acc.push_char(']'); - acc - } -} - #[cfg(test)] mod tests { use hashmap::HashMap; @@ -195,7 +176,6 @@ mod tests { assert_eq!(false.to_str(), ~"false"); assert_eq!(().to_str(), ~"()"); assert_eq!((~"hi").to_str(), ~"hi"); - assert_eq!((@"hi").to_str(), ~"hi"); } #[test] diff --git a/src/libstd/unstable/raw.rs b/src/libstd/unstable/raw.rs index 8aee26c24b2..63208b3f2d7 100644 --- a/src/libstd/unstable/raw.rs +++ b/src/libstd/unstable/raw.rs @@ -56,10 +56,8 @@ pub trait Repr<T> { impl<'a, T> Repr<Slice<T>> for &'a [T] {} impl<'a> Repr<Slice<u8>> for &'a str {} impl<T> Repr<*Box<T>> for @T {} -impl<T> Repr<*Box<Vec<T>>> for @[T] {} impl<T> Repr<*Vec<T>> for ~[T] {} impl Repr<*String> for ~str {} -impl Repr<*Box<String>> for @str {} // sure would be nice to have this // impl<T> Repr<*Vec<T>> for ~[T] {} diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 7e4405fd545..607b30c000b 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -646,13 +646,6 @@ pub mod traits { fn ne(&self, other: &~[T]) -> bool { !self.eq(other) } } - impl<T:Eq> Eq for @[T] { - #[inline] - fn eq(&self, other: &@[T]) -> bool { self.as_slice() == *other } - #[inline] - fn ne(&self, other: &@[T]) -> bool { !self.eq(other) } - } - impl<'a,T:TotalEq> TotalEq for &'a [T] { fn equals(&self, other: & &'a [T]) -> bool { self.len() == other.len() && @@ -665,11 +658,6 @@ pub mod traits { fn equals(&self, other: &~[T]) -> bool { self.as_slice().equals(&other.as_slice()) } } - impl<T:TotalEq> TotalEq for @[T] { - #[inline] - fn equals(&self, other: &@[T]) -> bool { self.as_slice().equals(&other.as_slice()) } - } - impl<'a,T:Eq, V: Vector<T>> Equiv<V> for &'a [T] { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } @@ -680,11 +668,6 @@ pub mod traits { fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } - impl<'a,T:Eq, V: Vector<T>> Equiv<V> for @[T] { - #[inline] - fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } - } - impl<'a,T:TotalOrd> TotalOrd for &'a [T] { fn cmp(&self, other: & &'a [T]) -> Ordering { order::cmp(self.iter(), other.iter()) @@ -696,11 +679,6 @@ pub mod traits { fn cmp(&self, other: &~[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) } } - impl<T: TotalOrd> TotalOrd for @[T] { - #[inline] - fn cmp(&self, other: &@[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) } - } - impl<'a, T: Eq + Ord> Ord for &'a [T] { fn lt(&self, other: & &'a [T]) -> bool { order::lt(self.iter(), other.iter()) @@ -730,17 +708,6 @@ pub mod traits { fn gt(&self, other: &~[T]) -> bool { self.as_slice() > other.as_slice() } } - impl<T: Eq + Ord> Ord for @[T] { - #[inline] - fn lt(&self, other: &@[T]) -> bool { self.as_slice() < other.as_slice() } - #[inline] - fn le(&self, other: &@[T]) -> bool { self.as_slice() <= other.as_slice() } - #[inline] - fn ge(&self, other: &@[T]) -> bool { self.as_slice() >= other.as_slice() } - #[inline] - fn gt(&self, other: &@[T]) -> bool { self.as_slice() > other.as_slice() } - } - impl<'a,T:Clone, V: Vector<T>> Add<V, ~[T]> for &'a [T] { #[inline] fn add(&self, rhs: &V) -> ~[T] { @@ -778,11 +745,6 @@ impl<T> Vector<T> for ~[T] { fn as_slice<'a>(&'a self) -> &'a [T] { let v: &'a [T] = *self; v } } -impl<T> Vector<T> for @[T] { - #[inline(always)] - fn as_slice<'a>(&'a self) -> &'a [T] { let v: &'a [T] = *self; v } -} - impl<'a, T> Container for &'a [T] { /// Returns the length of a vector #[inline] @@ -833,15 +795,6 @@ impl<T: Clone> CloneableVector<T> for ~[T] { fn into_owned(self) -> ~[T] { self } } -/// Extension methods for managed vectors -impl<T: Clone> CloneableVector<T> for @[T] { - #[inline] - fn to_owned(&self) -> ~[T] { self.as_slice().to_owned() } - - #[inline(always)] - fn into_owned(self) -> ~[T] { self.to_owned() } -} - /// Extension methods for vectors pub trait ImmutableVector<'a, T> { /** @@ -2637,10 +2590,6 @@ impl<A> Default for ~[A] { fn default() -> ~[A] { ~[] } } -impl<A> Default for @[A] { - fn default() -> @[A] { @[] } -} - macro_rules! iterator { (struct $name:ident -> $ptr:ty, $elem:ty) => { /// An iterator for iterating over a vector. @@ -3117,14 +3066,6 @@ mod tests { assert_eq!(v_b[0], 2); assert_eq!(v_b[1], 3); - // Test on managed heap. - let vec_managed = @[1, 2, 3, 4, 5]; - let v_c = vec_managed.slice(0u, 3u).to_owned(); - assert_eq!(v_c.len(), 3u); - assert_eq!(v_c[0], 1); - assert_eq!(v_c[1], 2); - assert_eq!(v_c[2], 3); - // Test on exchange heap. let vec_unique = ~[1, 2, 3, 4, 5, 6]; let v_d = vec_unique.slice(1u, 6u).to_owned(); @@ -4060,7 +4001,6 @@ mod tests { ); t!(&[int]); - t!(@[int]); t!(~[int]); } |
