Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary as[_mut]_slice/to_string() calls #19378

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f2af07e
libcollections: remove unnecessary `as_slice()` calls
Nov 27, 2014
0ac3b16
liballoc: remove unnecessary `as_slice()` calls
Nov 27, 2014
5257a5b
libcoretest: remove unnecessary `as_slice()` calls
Nov 27, 2014
0f54f32
libflate: remove unnecessary `as_slice()` calls
Nov 27, 2014
a796013
libfmt_macros: remove unnecessary `as_slice()` calls
Nov 27, 2014
6efc879
libgetops: remove unnecessary `as_slice()` calls
Nov 27, 2014
c0ef959
libgraphviz: remove unnecessary `as_slice()` calls
Nov 27, 2014
0ea3134
liblog: remove unnecessary `as_slice` calls
Nov 27, 2014
89e6a81
libregex: remove unnecessary `as_slice` calls
Nov 27, 2014
ae555a9
libregex_macros: remove unnecessary `as_slice` calls
Nov 27, 2014
00f3c3f
librustc: remove unnecessary `as_slice()` calls
Nov 27, 2014
7d8eabb
librustc_back: remove unnecessary `as_slice()` calls
Nov 27, 2014
8bb5ef9
librustc_trans: remove unnecessary `as_slice` calls
Nov 27, 2014
e6bd217
librustdoc: remove unnecessary `as_slice()` calls
Nov 27, 2014
09f7713
libserialize: remove unnecessary `as_slice()` calls
Nov 27, 2014
60338d9
libstd: remove unnecessary `as_slice()` calls
Nov 27, 2014
39f44c0
libsyntax: remove unnecessary `as_slice()` calls
Nov 27, 2014
53b479c
libterm: remove unnecessary `as_slice()` calls
Nov 27, 2014
a0621f8
libtest: remove unnecessary `as_slice()` calls
Nov 27, 2014
5a24058
libcollections: remove unnecessary `as_mut_slice()` calls
Nov 27, 2014
d64fd22
librustc: remove unnecessary `as_mut_slice` calls
Nov 27, 2014
a0a354f
librustc_trans: remove unnecessary `as_mut_slice` calls
Nov 27, 2014
5172981
librustdoc: remove unnecessary `as_mut_slice` calls
Nov 27, 2014
6132a90
libstd: remove unnecessary `as_mut_slice` calls
Nov 27, 2014
976660f
libtest: remove unnecessary `as_mut_slice()` calls
Nov 28, 2014
98ae637
libcollections: remove unnecessary `to_string()` calls
Nov 28, 2014
8379d72
libgetopts: remove unnecessary `to_string()` calls
Nov 28, 2014
71d8d57
librustc_back: remove unnecessary `to_string()` calls
Nov 28, 2014
ba01ea3
libserialize: remove unnecessary `to_string()` calls
Nov 28, 2014
c2da923
libstd: remove unnecessary `to_string()` calls
Nov 28, 2014
93e99b5
libsyntax: remove unnecessary `to_string()` calls
Nov 28, 2014
00c7786
libterm: remove unnecessary `to_string()` calls
Nov 28, 2014
66f52f4
libtest: remove unnecessary `to_string()` calls
Nov 28, 2014
2ed42bf
libtime: remove unnecessary `to_string()` calls
Nov 28, 2014
1fea900
Fix syntax error on android tests
Dec 7, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ mod tests {
#[test]
fn show_arc() {
let a = Arc::new(5u32);
assert!(format!("{}", a).as_slice() == "5")
assert!(format!("{}", a) == "5")
}

// Make sure deriving works with Arc<T>
Expand Down
8 changes: 4 additions & 4 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ mod test {
let b = box Test as Box<Any>;
let a_str = a.to_str();
let b_str = b.to_str();
assert_eq!(a_str.as_slice(), "Box<Any>");
assert_eq!(b_str.as_slice(), "Box<Any>");
assert_eq!(a_str, "Box<Any>");
assert_eq!(b_str, "Box<Any>");

let a = &8u as &Any;
let b = &Test as &Any;
let s = format!("{}", a);
assert_eq!(s.as_slice(), "&Any");
assert_eq!(s, "&Any");
let s = format!("{}", b);
assert_eq!(s.as_slice(), "&Any");
assert_eq!(s, "&Any");
}
}
8 changes: 4 additions & 4 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl<T: Ord> BinaryHeap<T> {
let mut end = q.len();
while end > 1 {
end -= 1;
q.data.as_mut_slice().swap(0, end);
q.data.swap(0, end);
q.siftdown_range(0, end)
}
q.into_vec()
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -2660,7 +2660,7 @@ mod tests {
s.insert(10);
s.insert(50);
s.insert(2);
assert_eq!("{1, 2, 10, 50}".to_string(), s.to_string());
assert_eq!("{1, 2, 10, 50}", s.to_string());
}

fn rng() -> rand::IsaacRng {
Expand Down
30 changes: 15 additions & 15 deletions src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,43 +158,43 @@ impl <K, V> Node<K, V> {
/// Swap the given key-value pair with the key-value pair stored in the node's index,
/// without checking bounds.
pub unsafe fn unsafe_swap(&mut self, index: uint, key: &mut K, val: &mut V) {
mem::swap(self.keys.as_mut_slice().unsafe_mut(index), key);
mem::swap(self.vals.as_mut_slice().unsafe_mut(index), val);
mem::swap(self.keys.unsafe_mut(index), key);
mem::swap(self.vals.unsafe_mut(index), val);
}

/// Get the node's key mutably without any bounds checks.
pub unsafe fn unsafe_key_mut(&mut self, index: uint) -> &mut K {
self.keys.as_mut_slice().unsafe_mut(index)
self.keys.unsafe_mut(index)
}

/// 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
pub fn edge_mut(&mut self, index: uint) -> Option<&mut Node<K,V>> {
self.edges.as_mut_slice().get_mut(index)
self.edges.get_mut(index)
}

/// Get the node's edge mutably without any bounds checks.
pub unsafe fn unsafe_edge_mut(&mut self, index: uint) -> &mut Node<K,V> {
self.edges.as_mut_slice().unsafe_mut(index)
self.edges.unsafe_mut(index)
}

/// Pop an edge off the end of the node
Expand Down Expand Up @@ -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,
Expand All @@ -292,8 +292,8 @@ 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()),
edges: self.edges.as_mut_slice().iter_mut(),
elems: self.keys.iter().zip(self.vals.iter_mut()),
edges: self.edges.iter_mut(),
head_is_edge: true,
tail_is_edge: true,
has_edges: !is_leaf,
Expand Down Expand Up @@ -477,8 +477,8 @@ 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 right_ptr = right.as_mut_slice().as_mut_ptr();
let left_ptr = left.unsafe_get(left_len) as *const _;
let right_ptr = right.as_mut_ptr();
ptr::copy_nonoverlapping_memory(right_ptr, left_ptr, right_len);
left.set_len(left_len);
right.set_len(right_len);
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ mod test {

let set_str = format!("{}", set);

assert!(set_str == "{1, 2}".to_string());
assert_eq!(format!("{}", empty), "{}".to_string());
assert!(set_str == "{1, 2}");
assert_eq!(format!("{}", empty), "{}");
}
}
8 changes: 4 additions & 4 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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>>());
});
}

Expand Down Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions src/libcollections/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,15 +1246,15 @@ 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) {
d.push_front(i);
}
{
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();
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
Loading