libcollections: remove unnecessary as_slice() calls

This commit is contained in:
Jorge Aparicio 2014-11-27 11:45:50 -05:00
parent de83d7dd19
commit f2af07e6d5
11 changed files with 123 additions and 126 deletions

View File

@ -769,8 +769,8 @@ mod tests {
v.sort();
data.sort();
assert_eq!(v.as_slice(), data.as_slice());
assert_eq!(heap.into_sorted_vec().as_slice(), data.as_slice());
assert_eq!(v, data);
assert_eq!(heap.into_sorted_vec(), data);
}
#[test]
@ -812,7 +812,7 @@ mod tests {
fn test_from_iter() {
let xs = vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1);
let mut q: BinaryHeap<uint> = xs.as_slice().iter().rev().map(|&x| x).collect();
let mut q: BinaryHeap<uint> = xs.iter().rev().map(|&x| x).collect();
for &x in xs.iter() {
assert_eq!(q.pop().unwrap(), x);

View File

@ -1692,10 +1692,10 @@ mod tests {
#[test]
fn test_to_str() {
let zerolen = Bitv::new();
assert_eq!(zerolen.to_string().as_slice(), "");
assert_eq!(zerolen.to_string(), "");
let eightbits = Bitv::with_capacity(8u, false);
assert_eq!(eightbits.to_string().as_slice(), "00000000")
assert_eq!(eightbits.to_string(), "00000000")
}
#[test]
@ -1718,7 +1718,7 @@ mod tests {
let mut b = bitv::Bitv::with_capacity(2, false);
b.set(0, true);
b.set(1, false);
assert_eq!(b.to_string().as_slice(), "10");
assert_eq!(b.to_string(), "10");
}
#[test]
@ -2029,7 +2029,7 @@ mod tests {
fn test_from_bytes() {
let bitv = from_bytes(&[0b10110110, 0b00000000, 0b11111111]);
let str = format!("{}{}{}", "10110110", "00000000", "11111111");
assert_eq!(bitv.to_string().as_slice(), str.as_slice());
assert_eq!(bitv.to_string(), str);
}
#[test]
@ -2048,7 +2048,7 @@ mod tests {
fn test_from_bools() {
let bools = vec![true, false, true, true];
let bitv: Bitv = bools.iter().map(|n| *n).collect();
assert_eq!(bitv.to_string().as_slice(), "1011");
assert_eq!(bitv.to_string(), "1011");
}
#[test]
@ -2207,7 +2207,7 @@ mod tests {
let expected = [3, 5, 11, 77];
let actual = a.intersection(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
assert_eq!(actual, expected);
}
#[test]
@ -2226,7 +2226,7 @@ mod tests {
let expected = [1, 5, 500];
let actual = a.difference(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
assert_eq!(actual, expected);
}
#[test]
@ -2247,7 +2247,7 @@ mod tests {
let expected = [1, 5, 11, 14, 220];
let actual = a.symmetric_difference(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
assert_eq!(actual, expected);
}
#[test]
@ -2272,7 +2272,7 @@ mod tests {
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160, 200];
let actual = a.union(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
assert_eq!(actual, expected);
}
#[test]

View File

@ -169,22 +169,22 @@ impl <K, V> Node<K, V> {
/// Get the node's value at the given index
pub fn val(&self, index: uint) -> Option<&V> {
self.vals.as_slice().get(index)
self.vals.get(index)
}
/// Get the node's value at the given index
pub fn val_mut(&mut self, index: uint) -> Option<&mut V> {
self.vals.as_mut_slice().get_mut(index)
self.vals.get_mut(index)
}
/// Get the node's value mutably without any bounds checks.
pub unsafe fn unsafe_val_mut(&mut self, index: uint) -> &mut V {
self.vals.as_mut_slice().unsafe_mut(index)
self.vals.unsafe_mut(index)
}
/// Get the node's edge at the given index
pub fn edge(&self, index: uint) -> Option<&Node<K,V>> {
self.edges.as_slice().get(index)
self.edges.get(index)
}
/// Get the node's edge mutably at the given index
@ -281,8 +281,8 @@ impl <K, V> Node<K, V> {
pub fn iter<'a>(&'a self) -> Traversal<'a, K, V> {
let is_leaf = self.is_leaf();
Traversal {
elems: self.keys.as_slice().iter().zip(self.vals.as_slice().iter()),
edges: self.edges.as_slice().iter(),
elems: self.keys.iter().zip(self.vals.iter()),
edges: self.edges.iter(),
head_is_edge: true,
tail_is_edge: true,
has_edges: !is_leaf,
@ -292,7 +292,7 @@ impl <K, V> Node<K, V> {
pub fn iter_mut<'a>(&'a mut self) -> MutTraversal<'a, K, V> {
let is_leaf = self.is_leaf();
MutTraversal {
elems: self.keys.as_slice().iter().zip(self.vals.as_mut_slice().iter_mut()),
elems: self.keys.iter().zip(self.vals.as_mut_slice().iter_mut()),
edges: self.edges.as_mut_slice().iter_mut(),
head_is_edge: true,
tail_is_edge: true,
@ -477,7 +477,7 @@ fn split<T>(left: &mut Vec<T>) -> Vec<T> {
let left_len = len - right_len;
let mut right = Vec::with_capacity(left.capacity());
unsafe {
let left_ptr = left.as_slice().unsafe_get(left_len) as *const _;
let left_ptr = left.unsafe_get(left_len) as *const _;
let right_ptr = right.as_mut_slice().as_mut_ptr();
ptr::copy_nonoverlapping_memory(right_ptr, left_ptr, right_len);
left.set_len(left_len);

View File

@ -926,7 +926,7 @@ mod tests {
let mut m = list_from(v.as_slice());
m.prepend(list_from(u.as_slice()));
check_links(&m);
u.extend(v.as_slice().iter().map(|&b| b));
u.extend(v.iter().map(|&b| b));
assert_eq!(u.len(), m.len());
for elt in u.into_iter() {
assert_eq!(m.pop_front(), Some(elt))
@ -1133,7 +1133,7 @@ mod tests {
spawn(proc() {
check_links(&n);
let a: &[_] = &[&1,&2,&3];
assert_eq!(a, n.iter().collect::<Vec<&int>>().as_slice());
assert_eq!(a, n.iter().collect::<Vec<&int>>());
});
}
@ -1224,12 +1224,12 @@ mod tests {
#[test]
fn test_show() {
let list: DList<int> = range(0i, 10).collect();
assert!(list.to_string().as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
assert!(list.to_string() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
.map(|&s| s)
.collect();
assert!(list.to_string().as_slice() == "[just, one, test, more]");
assert!(list.to_string() == "[just, one, test, more]");
}
#[cfg(test)]

View File

@ -288,11 +288,11 @@ mod test {
#[test]
fn test_show() {
let mut e = EnumSet::new();
assert_eq!("{}", e.to_string().as_slice());
assert_eq!("{}", e.to_string());
e.insert(A);
assert_eq!("{A}", e.to_string().as_slice());
assert_eq!("{A}", e.to_string());
e.insert(C);
assert_eq!("{A, C}", e.to_string().as_slice());
assert_eq!("{A, C}", e.to_string());
}
#[test]

View File

@ -1246,7 +1246,7 @@ mod tests {
}
{
let b: &[_] = &[&0,&1,&2,&3,&4];
assert_eq!(d.iter().collect::<Vec<&int>>().as_slice(), b);
assert_eq!(d.iter().collect::<Vec<&int>>(), b);
}
for i in range(6i, 9) {
@ -1254,7 +1254,7 @@ mod tests {
}
{
let b: &[_] = &[&8,&7,&6,&0,&1,&2,&3,&4];
assert_eq!(d.iter().collect::<Vec<&int>>().as_slice(), b);
assert_eq!(d.iter().collect::<Vec<&int>>(), b);
}
let mut it = d.iter();
@ -1277,14 +1277,14 @@ mod tests {
}
{
let b: &[_] = &[&4,&3,&2,&1,&0];
assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), b);
assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b);
}
for i in range(6i, 9) {
d.push_front(i);
}
let b: &[_] = &[&4,&3,&2,&1,&0,&6,&7,&8];
assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), b);
assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b);
}
#[test]
@ -1495,12 +1495,12 @@ mod tests {
#[test]
fn test_show() {
let ringbuf: RingBuf<int> = range(0i, 10).collect();
assert!(format!("{}", ringbuf).as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
assert!(format!("{}", ringbuf) == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter()
.map(|&s| s)
.collect();
assert!(format!("{}", ringbuf).as_slice() == "[just, one, test, more]");
assert!(format!("{}", ringbuf) == "[just, one, test, more]");
}
#[test]

View File

@ -1652,24 +1652,24 @@ mod tests {
let xs = &[1i,2,3,4,5];
let splits: &[&[int]] = &[&[1], &[3], &[5]];
assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[], &[2,3,4,5]];
assert_eq!(xs.split(|x| *x == 1).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|x| *x == 1).collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[1,2,3,4], &[]];
assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[1,2,3,4,5]];
assert_eq!(xs.split(|x| *x == 10).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|x| *x == 10).collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[], &[], &[], &[], &[], &[]];
assert_eq!(xs.split(|_| true).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|_| true).collect::<Vec<&[int]>>(),
splits);
let xs: &[int] = &[];
let splits: &[&[int]] = &[&[]];
assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits);
assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>(), splits);
}
#[test]
@ -1677,18 +1677,18 @@ mod tests {
let xs = &[1i,2,3,4,5];
let splits: &[&[int]] = &[&[1,2,3,4,5]];
assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[1], &[3,4,5]];
assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[], &[], &[], &[4,5]];
assert_eq!(xs.splitn(3, |_| true).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.splitn(3, |_| true).collect::<Vec<&[int]>>(),
splits);
let xs: &[int] = &[];
let splits: &[&[int]] = &[&[]];
assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits);
assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>(), splits);
}
#[test]
@ -1696,18 +1696,18 @@ mod tests {
let xs = &mut [1i,2,3,4,5];
let splits: &[&mut [int]] = &[&mut [1,2,3,4,5]];
assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(),
assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(),
splits);
let splits: &[&mut [int]] = &[&mut [1], &mut [3,4,5]];
assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(),
assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(),
splits);
let splits: &[&mut [int]] = &[&mut [], &mut [], &mut [], &mut [4,5]];
assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>().as_slice(),
assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>(),
splits);
let xs: &mut [int] = &mut [];
let splits: &[&mut [int]] = &[&mut []];
assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>().as_slice(),
assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>(),
splits);
}
@ -1716,21 +1716,21 @@ mod tests {
let xs = &[1i,2,3,4,5];
let splits: &[&[int]] = &[&[5], &[3], &[1]];
assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[2,3,4,5], &[]];
assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[], &[1,2,3,4]];
assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[1,2,3,4,5]];
assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<&[int]>>(),
splits);
let xs: &[int] = &[];
let splits: &[&[int]] = &[&[]];
assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>().as_slice(), splits);
assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>(), splits);
}
#[test]
@ -1738,18 +1738,18 @@ mod tests {
let xs = &[1,2,3,4,5];
let splits: &[&[int]] = &[&[1,2,3,4,5]];
assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[5], &[1,2,3]];
assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits);
let splits: &[&[int]] = &[&[], &[], &[], &[1,2]];
assert_eq!(xs.rsplitn(3, |_| true).collect::<Vec<&[int]>>().as_slice(),
assert_eq!(xs.rsplitn(3, |_| true).collect::<Vec<&[int]>>(),
splits);
let xs: &[int] = &[];
let splits: &[&[int]] = &[&[]];
assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits);
assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<Vec<&[int]>>(), splits);
}
#[test]
@ -1757,9 +1757,9 @@ mod tests {
let v = &[1i,2,3,4];
let wins: &[&[int]] = &[&[1,2], &[2,3], &[3,4]];
assert_eq!(v.windows(2).collect::<Vec<&[int]>>().as_slice(), wins);
assert_eq!(v.windows(2).collect::<Vec<&[int]>>(), wins);
let wins: &[&[int]] = &[&[1i,2,3], &[2,3,4]];
assert_eq!(v.windows(3).collect::<Vec<&[int]>>().as_slice(), wins);
assert_eq!(v.windows(3).collect::<Vec<&[int]>>(), wins);
assert!(v.windows(6).next().is_none());
}
@ -1775,14 +1775,14 @@ mod tests {
let v = &[1i,2,3,4,5];
let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]];
assert_eq!(v.chunks(2).collect::<Vec<&[int]>>().as_slice(), chunks);
assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks);
let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]];
assert_eq!(v.chunks(3).collect::<Vec<&[int]>>().as_slice(), chunks);
assert_eq!(v.chunks(3).collect::<Vec<&[int]>>(), chunks);
let chunks: &[&[int]] = &[&[1i,2,3,4,5]];
assert_eq!(v.chunks(6).collect::<Vec<&[int]>>().as_slice(), chunks);
assert_eq!(v.chunks(6).collect::<Vec<&[int]>>(), chunks);
let chunks: &[&[int]] = &[&[5i], &[3,4], &[1,2]];
assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>().as_slice(), chunks);
assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>(), chunks);
let mut it = v.chunks(2);
assert_eq!(it.indexable(), 3);
let chunk: &[int] = &[1,2];
@ -2081,7 +2081,7 @@ mod tests {
fn test_to_vec() {
let xs = box [1u, 2, 3];
let ys = xs.to_vec();
assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice());
assert_eq!(ys, [1u, 2, 3]);
}
}

View File

@ -215,7 +215,7 @@ pub struct Decompositions<'a> {
impl<'a> Iterator<char> for Decompositions<'a> {
#[inline]
fn next(&mut self) -> Option<char> {
match self.buffer.as_slice().head() {
match self.buffer.head() {
Some(&(c, 0)) => {
self.sorted = false;
self.buffer.remove(0);
@ -913,10 +913,10 @@ mod tests {
#[test]
fn test_collect() {
let empty = String::from_str("");
let s: String = empty.as_slice().chars().collect();
let s: String = empty.chars().collect();
assert_eq!(empty, s);
let data = String::from_str("ประเทศไทย中");
let s: String = data.as_slice().chars().collect();
let s: String = data.chars().collect();
assert_eq!(data, s);
}
@ -924,7 +924,7 @@ mod tests {
fn test_into_bytes() {
let data = String::from_str("asdf");
let buf = data.into_bytes();
assert_eq!(b"asdf", buf.as_slice());
assert_eq!(b"asdf", buf);
}
#[test]
@ -941,21 +941,21 @@ mod tests {
let string = "ประเทศไทย中华Việt Nam";
let mut data = String::from_str(string);
data.push_str(string);
assert!(data.as_slice().find_str("ไท华").is_none());
assert_eq!(data.as_slice().slice(0u, 43u).find_str(""), Some(0u));
assert_eq!(data.as_slice().slice(6u, 43u).find_str(""), Some(6u - 6u));
assert!(data.find_str("ไท华").is_none());
assert_eq!(data.slice(0u, 43u).find_str(""), Some(0u));
assert_eq!(data.slice(6u, 43u).find_str(""), Some(6u - 6u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("ประ"), Some( 0u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("ทศไ"), Some(12u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("ย中"), Some(24u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("iệt"), Some(34u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("Nam"), Some(40u));
assert_eq!(data.slice(0u, 43u).find_str("ประ"), Some( 0u));
assert_eq!(data.slice(0u, 43u).find_str("ทศไ"), Some(12u));
assert_eq!(data.slice(0u, 43u).find_str("ย中"), Some(24u));
assert_eq!(data.slice(0u, 43u).find_str("iệt"), Some(34u));
assert_eq!(data.slice(0u, 43u).find_str("Nam"), Some(40u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("ประ"), Some(43u - 43u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("ย中"), Some(67u - 43u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("iệt"), Some(77u - 43u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("Nam"), Some(83u - 43u));
assert_eq!(data.slice(43u, 86u).find_str("ประ"), Some(43u - 43u));
assert_eq!(data.slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u));
assert_eq!(data.slice(43u, 86u).find_str("ย中"), Some(67u - 43u));
assert_eq!(data.slice(43u, 86u).find_str("iệt"), Some(77u - 43u));
assert_eq!(data.slice(43u, 86u).find_str("Nam"), Some(83u - 43u));
}
#[test]
@ -987,7 +987,7 @@ mod tests {
($expected: expr, $string: expr) => {
{
let s = $string.concat();
assert_eq!($expected, s.as_slice());
assert_eq!($expected, s);
}
}
}
@ -1025,7 +1025,7 @@ mod tests {
($expected: expr, $string: expr, $delim: expr) => {
{
let s = $string.connect($delim);
assert_eq!($expected, s.as_slice());
assert_eq!($expected, s);
}
}
}
@ -1146,7 +1146,7 @@ mod tests {
let a = "ประเ";
let a2 = "دولة الكويتทศไทย中华";
assert_eq!(data.replace(a, repl).as_slice(), a2);
assert_eq!(data.replace(a, repl), a2);
}
#[test]
@ -1156,7 +1156,7 @@ mod tests {
let b = "ะเ";
let b2 = "ปรدولة الكويتทศไทย中华";
assert_eq!(data.replace(b, repl).as_slice(), b2);
assert_eq!(data.replace(b, repl), b2);
}
#[test]
@ -1166,7 +1166,7 @@ mod tests {
let c = "中华";
let c2 = "ประเทศไทยدولة الكويت";
assert_eq!(data.replace(c, repl).as_slice(), c2);
assert_eq!(data.replace(c, repl), c2);
}
#[test]
@ -1175,7 +1175,7 @@ mod tests {
let repl = "دولة الكويت";
let d = "ไท华";
assert_eq!(data.replace(d, repl).as_slice(), data);
assert_eq!(data.replace(d, repl), data);
}
#[test]
@ -1211,7 +1211,7 @@ mod tests {
}
let letters = a_million_letter_x();
assert!(half_a_million_letter_x() ==
String::from_str(letters.as_slice().slice(0u, 3u * 500000u)));
String::from_str(letters.slice(0u, 3u * 500000u)));
}
#[test]
@ -1450,7 +1450,7 @@ mod tests {
let b: &[u8] = &[];
assert_eq!("".as_bytes(), b);
assert_eq!("abc".as_bytes(), b"abc");
assert_eq!("ศไทย中华Việt Nam".as_bytes(), v.as_slice());
assert_eq!("ศไทย中华Việt Nam".as_bytes(), v);
}
#[test]
@ -1485,7 +1485,6 @@ mod tests {
let string = "a\nb\nc";
let lines: Vec<&str> = string.lines().collect();
let lines = lines.as_slice();
assert_eq!(string.subslice_offset(lines[0]), 0);
assert_eq!(string.subslice_offset(lines[1]), 2);
assert_eq!(string.subslice_offset(lines[2]), 4);
@ -2181,10 +2180,10 @@ mod tests {
let s = "a̐éö̲\r\n";
let gr_inds = s.grapheme_indices(true).collect::<Vec<(uint, &str)>>();
let b: &[_] = &[(0u, ""), (3, ""), (6, "ö̲"), (11, "\r\n")];
assert_eq!(gr_inds.as_slice(), b);
assert_eq!(gr_inds, b);
let gr_inds = s.grapheme_indices(true).rev().collect::<Vec<(uint, &str)>>();
let b: &[_] = &[(11, "\r\n"), (6, "ö̲"), (3, ""), (0u, "")];
assert_eq!(gr_inds.as_slice(), b);
assert_eq!(gr_inds, b);
let mut gr_inds_iter = s.grapheme_indices(true);
{
let gr_inds = gr_inds_iter.by_ref();
@ -2200,14 +2199,14 @@ mod tests {
let s = "\n\r\n\r";
let gr = s.graphemes(true).rev().collect::<Vec<&str>>();
let b: &[_] = &["\r", "\r\n", "\n"];
assert_eq!(gr.as_slice(), b);
assert_eq!(gr, b);
}
#[test]
fn test_split_strator() {
fn t(s: &str, sep: &str, u: &[&str]) {
let v: Vec<&str> = s.split_str(sep).collect();
assert_eq!(v.as_slice(), u.as_slice());
assert_eq!(v, u);
}
t("--1233345--", "12345", &["--1233345--"]);
t("abc::hello::there", "::", &["abc", "hello", "there"]);

View File

@ -559,7 +559,7 @@ impl String {
#[inline]
#[unstable = "the panic conventions for strings are under development"]
pub fn truncate(&mut self, new_len: uint) {
assert!(self.as_slice().is_char_boundary(new_len));
assert!(self.is_char_boundary(new_len));
self.vec.truncate(new_len)
}
@ -583,7 +583,7 @@ impl String {
return None
}
let CharRange {ch, next} = self.as_slice().char_range_at_reverse(len);
let CharRange {ch, next} = self.char_range_at_reverse(len);
unsafe {
self.vec.set_len(next);
}
@ -618,7 +618,7 @@ impl String {
let len = self.len();
if idx >= len { return None }
let CharRange { ch, next } = self.as_slice().char_range_at(idx);
let CharRange { ch, next } = self.char_range_at(idx);
unsafe {
ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as int),
self.vec.as_ptr().offset(next as int),
@ -643,7 +643,7 @@ impl String {
pub fn insert(&mut self, idx: uint, ch: char) {
let len = self.len();
assert!(idx <= len);
assert!(self.as_slice().is_char_boundary(idx));
assert!(self.is_char_boundary(idx));
self.vec.reserve(4);
let mut bits = [0, ..4];
let amt = ch.encode_utf8(&mut bits).unwrap();
@ -1092,7 +1092,7 @@ mod tests {
for p in pairs.iter() {
let (s, u) = (*p).clone();
let s_as_utf16 = s.as_slice().utf16_units().collect::<Vec<u16>>();
let s_as_utf16 = s.utf16_units().collect::<Vec<u16>>();
let u_as_string = String::from_utf16(u.as_slice()).unwrap();
assert!(str::is_utf16(u.as_slice()));
@ -1102,7 +1102,7 @@ mod tests {
assert_eq!(String::from_utf16_lossy(u.as_slice()), s);
assert_eq!(String::from_utf16(s_as_utf16.as_slice()).unwrap(), s);
assert_eq!(u_as_string.as_slice().utf16_units().collect::<Vec<u16>>(), u);
assert_eq!(u_as_string.utf16_units().collect::<Vec<u16>>(), u);
}
}
@ -1162,18 +1162,18 @@ mod tests {
let mv = s.as_mut_vec();
mv.push_all(&[b'D']);
}
assert_eq!(s.as_slice(), "ABCD");
assert_eq!(s, "ABCD");
}
#[test]
fn test_push_str() {
let mut s = String::new();
s.push_str("");
assert_eq!(s.as_slice().slice_from(0), "");
assert_eq!(s.slice_from(0), "");
s.push_str("abc");
assert_eq!(s.as_slice().slice_from(0), "abc");
assert_eq!(s.slice_from(0), "abc");
s.push_str("ประเทศไทย中华Việt Nam");
assert_eq!(s.as_slice().slice_from(0), "abcประเทศไทย中华Việt Nam");
assert_eq!(s.slice_from(0), "abcประเทศไทย中华Việt Nam");
}
#[test]
@ -1184,7 +1184,7 @@ mod tests {
data.push('¢'); // 2 byte
data.push('€'); // 3 byte
data.push('𤭢'); // 4 byte
assert_eq!(data.as_slice(), "ประเทศไทย中华b¢€𤭢");
assert_eq!(data, "ประเทศไทย中华b¢€𤭢");
}
#[test]
@ -1195,24 +1195,24 @@ mod tests {
assert_eq!(data.pop().unwrap(), '¢'); // 2 bytes
assert_eq!(data.pop().unwrap(), 'b'); // 1 bytes
assert_eq!(data.pop().unwrap(), '华');
assert_eq!(data.as_slice(), "ประเทศไทย中");
assert_eq!(data, "ประเทศไทย中");
}
#[test]
fn test_str_truncate() {
let mut s = String::from_str("12345");
s.truncate(5);
assert_eq!(s.as_slice(), "12345");
assert_eq!(s, "12345");
s.truncate(3);
assert_eq!(s.as_slice(), "123");
assert_eq!(s, "123");
s.truncate(0);
assert_eq!(s.as_slice(), "");
assert_eq!(s, "");
let mut s = String::from_str("12345");
let p = s.as_slice().as_ptr();
let p = s.as_ptr();
s.truncate(3);
s.push_str("6");
let p_ = s.as_slice().as_ptr();
let p_ = s.as_ptr();
assert_eq!(p_, p);
}
@ -1235,7 +1235,7 @@ mod tests {
let mut s = String::from_str("12345");
s.clear();
assert_eq!(s.len(), 0);
assert_eq!(s.as_slice(), "");
assert_eq!(s, "");
}
#[test]
@ -1244,7 +1244,7 @@ mod tests {
let b = a + "2";
let b = b + String::from_str("2");
assert_eq!(b.len(), 7);
assert_eq!(b.as_slice(), "1234522");
assert_eq!(b, "1234522");
}
#[test]
@ -1252,11 +1252,11 @@ mod tests {
let mut s = "ศไทย中华Việt Nam; foobar".to_string();;
assert_eq!(s.remove(0), Some('ศ'));
assert_eq!(s.len(), 33);
assert_eq!(s.as_slice(), "ไทย中华Việt Nam; foobar");
assert_eq!(s, "ไทย中华Việt Nam; foobar");
assert_eq!(s.remove(33), None);
assert_eq!(s.remove(300), None);
assert_eq!(s.remove(17), Some('ệ'));
assert_eq!(s.as_slice(), "ไทย中华Vit Nam; foobar");
assert_eq!(s, "ไทย中华Vit Nam; foobar");
}
#[test] #[should_fail]
@ -1268,9 +1268,9 @@ mod tests {
fn insert() {
let mut s = "foobar".to_string();
s.insert(0, 'ệ');
assert_eq!(s.as_slice(), "ệfoobar");
assert_eq!(s, "ệfoobar");
s.insert(6, 'ย');
assert_eq!(s.as_slice(), "ệfooยbar");
assert_eq!(s, "ệfooยbar");
}
#[test] #[should_fail] fn insert_bad1() { "".to_string().insert(1, 't'); }

View File

@ -798,7 +798,7 @@ impl<T> Vec<T> {
// decrement len before the read(), so a panic on Drop doesn't
// re-drop the just-failed value.
self.len -= 1;
ptr::read(self.as_slice().unsafe_get(self.len));
ptr::read(self.unsafe_get(self.len));
}
}
}
@ -1091,7 +1091,7 @@ impl<T> Vec<T> {
} else {
unsafe {
self.len -= 1;
Some(ptr::read(self.as_slice().unsafe_get(self.len())))
Some(ptr::read(self.unsafe_get(self.len())))
}
}
}
@ -1779,7 +1779,7 @@ mod tests {
#[test]
fn test_as_vec() {
let xs = [1u8, 2u8, 3u8];
assert_eq!(as_vec(&xs).as_slice(), xs.as_slice());
assert_eq!(as_vec(&xs).as_slice(), xs);
}
#[test]
@ -1875,7 +1875,7 @@ mod tests {
}
}
assert!(values.as_slice() == [1, 2, 5, 6, 7]);
assert!(values == [1, 2, 5, 6, 7]);
}
#[test]
@ -1889,7 +1889,7 @@ mod tests {
}
}
assert!(values.as_slice() == [2, 3, 3, 4, 5]);
assert!(values == [2, 3, 3, 4, 5]);
}
#[test]
@ -2019,7 +2019,6 @@ mod tests {
let (left, right) = unzip(z1.iter().map(|&x| x));
let (left, right) = (left.as_slice(), right.as_slice());
assert_eq!((1, 4), (left[0], right[0]));
assert_eq!((2, 5), (left[1], right[1]));
assert_eq!((3, 6), (left[2], right[2]));
@ -2153,7 +2152,7 @@ mod tests {
#[test]
fn test_map_in_place() {
let v = vec![0u, 1, 2];
assert_eq!(v.map_in_place(|i: uint| i as int - 1).as_slice(), [-1i, 0, 1].as_slice());
assert_eq!(v.map_in_place(|i: uint| i as int - 1), [-1i, 0, 1]);
}
#[test]
@ -2161,7 +2160,7 @@ mod tests {
let v = vec![(), ()];
#[deriving(PartialEq, Show)]
struct ZeroSized;
assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice());
assert_eq!(v.map_in_place(|_| ZeroSized), [ZeroSized, ZeroSized]);
}
#[test]
@ -2198,7 +2197,7 @@ mod tests {
fn test_into_boxed_slice() {
let xs = vec![1u, 2, 3];
let ys = xs.into_boxed_slice();
assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice());
assert_eq!(ys.as_slice(), [1u, 2, 3]);
}
#[bench]

View File

@ -870,7 +870,6 @@ mod test_map {
map.insert(3, 4i);
let map_str = map.to_string();
let map_str = map_str.as_slice();
assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
assert_eq!(format!("{}", empty), "{}".to_string());
}