libcollections: remove unnecessary as_mut_slice() calls

This commit is contained in:
Jorge Aparicio 2014-11-27 16:44:57 -05:00
parent a0621f8eba
commit 5a24058889
4 changed files with 32 additions and 32 deletions

View File

@ -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()

View File

@ -158,13 +158,13 @@ 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
@ -189,12 +189,12 @@ impl <K, V> Node<K, V> {
/// 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
@ -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.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,
@ -478,7 +478,7 @@ fn split<T>(left: &mut Vec<T>) -> Vec<T> {
let mut right = Vec::with_capacity(left.capacity());
unsafe {
let left_ptr = left.unsafe_get(left_len) as *const _;
let right_ptr = right.as_mut_slice().as_mut_ptr();
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);

View File

@ -201,7 +201,7 @@ impl Iterator<(uint, uint)> for ElementSwaps {
match max {
Some((i, sd)) => {
let j = new_pos(i, sd.dir);
self.sdir.as_mut_slice().swap(i, j);
self.sdir.swap(i, j);
// Swap the direction of each larger SizeDirection
for x in self.sdir.iter_mut() {
@ -256,7 +256,7 @@ impl<T: Clone> Iterator<Vec<T>> for Permutations<T> {
Some((0,0)) => Some(self.v.clone()),
Some((a, b)) => {
let elt = self.v.clone();
self.v.as_mut_slice().swap(a, b);
self.v.swap(a, b);
Some(elt)
}
}
@ -779,11 +779,11 @@ mod tests {
#[test]
fn test_head_mut() {
let mut a = vec![];
assert_eq!(a.as_mut_slice().head_mut(), None);
assert_eq!(a.head_mut(), None);
a = vec![11i];
assert_eq!(*a.as_mut_slice().head_mut().unwrap(), 11);
assert_eq!(*a.head_mut().unwrap(), 11);
a = vec![11i, 12];
assert_eq!(*a.as_mut_slice().head_mut().unwrap(), 11);
assert_eq!(*a.head_mut().unwrap(), 11);
}
#[test]
@ -800,10 +800,10 @@ mod tests {
fn test_tail_mut() {
let mut a = vec![11i];
let b: &mut [int] = &mut [];
assert!(a.as_mut_slice().tail_mut() == b);
assert!(a.tail_mut() == b);
a = vec![11i, 12];
let b: &mut [int] = &mut [12];
assert!(a.as_mut_slice().tail_mut() == b);
assert!(a.tail_mut() == b);
}
#[test]
@ -817,7 +817,7 @@ mod tests {
#[should_fail]
fn test_tail_mut_empty() {
let mut a: Vec<int> = vec![];
a.as_mut_slice().tail_mut();
a.tail_mut();
}
#[test]
@ -834,10 +834,10 @@ mod tests {
fn test_init_mut() {
let mut a = vec![11i];
let b: &mut [int] = &mut [];
assert!(a.as_mut_slice().init_mut() == b);
assert!(a.init_mut() == b);
a = vec![11i, 12];
let b: &mut [int] = &mut [11];
assert!(a.as_mut_slice().init_mut() == b);
assert!(a.init_mut() == b);
}
#[test]
@ -851,7 +851,7 @@ mod tests {
#[should_fail]
fn test_init_mut_empty() {
let mut a: Vec<int> = vec![];
a.as_mut_slice().init_mut();
a.init_mut();
}
#[test]
@ -867,11 +867,11 @@ mod tests {
#[test]
fn test_last_mut() {
let mut a = vec![];
assert_eq!(a.as_mut_slice().last_mut(), None);
assert_eq!(a.last_mut(), None);
a = vec![11i];
assert_eq!(*a.as_mut_slice().last_mut().unwrap(), 11);
assert_eq!(*a.last_mut().unwrap(), 11);
a = vec![11i, 12];
assert_eq!(*a.as_mut_slice().last_mut().unwrap(), 12);
assert_eq!(*a.last_mut().unwrap(), 12);
}
#[test]
@ -1299,13 +1299,13 @@ mod tests {
.collect::<Vec<uint>>();
let mut v1 = v.clone();
v.as_mut_slice().sort();
v.sort();
assert!(v.as_slice().windows(2).all(|w| w[0] <= w[1]));
v1.as_mut_slice().sort_by(|a, b| a.cmp(b));
v1.sort_by(|a, b| a.cmp(b));
assert!(v1.as_slice().windows(2).all(|w| w[0] <= w[1]));
v1.as_mut_slice().sort_by(|a, b| b.cmp(a));
v1.sort_by(|a, b| b.cmp(a));
assert!(v1.as_slice().windows(2).all(|w| w[0] >= w[1]));
}
}

View File

@ -211,7 +211,7 @@ impl<T> Vec<T> {
let mut xs = Vec::with_capacity(length);
while xs.len < length {
let len = xs.len;
ptr::write(xs.as_mut_slice().unsafe_mut(len), op(len));
ptr::write(xs.unsafe_mut(len), op(len));
xs.len += 1;
}
xs
@ -328,7 +328,7 @@ impl<T: Clone> Vec<T> {
let mut xs = Vec::with_capacity(length);
while xs.len < length {
let len = xs.len;
ptr::write(xs.as_mut_slice().unsafe_mut(len),
ptr::write(xs.unsafe_mut(len),
value.clone());
xs.len += 1;
}
@ -361,7 +361,7 @@ impl<T: Clone> Vec<T> {
// during the loop can prevent this optimisation.
unsafe {
ptr::write(
self.as_mut_slice().unsafe_mut(len),
self.unsafe_mut(len),
other.unsafe_get(i).clone());
self.set_len(len + 1);
}
@ -896,7 +896,7 @@ impl<T> Vec<T> {
pub fn swap_remove(&mut self, index: uint) -> Option<T> {
let length = self.len();
if length > 0 && index < length - 1 {
self.as_mut_slice().swap(index, length - 1);
self.swap(index, length - 1);
} else if index >= length {
return None
}
@ -1231,7 +1231,7 @@ impl<T: PartialEq> Vec<T> {
if ln < 1 { return; }
// Avoid bounds checks by using unsafe pointers.
let p = self.as_mut_slice().as_mut_ptr();
let p = self.as_mut_ptr();
let mut r = 1;
let mut w = 1;
@ -1293,7 +1293,7 @@ impl<T> Drop for Vec<T> {
// zeroed (when moving out, because of #[unsafe_no_drop_flag]).
if self.cap != 0 {
unsafe {
for x in self.as_mut_slice().iter() {
for x in self.iter() {
ptr::read(x);
}
dealloc(self.ptr, self.cap)