diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2014-11-27 16:44:57 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2014-12-06 23:53:01 -0500 |
| commit | 5a240588895b733f4e41fb8f9cb0a3d2f80b1e87 (patch) | |
| tree | b1bc74ebe26001d129211dc2982888fd14b4aaf4 | |
| parent | a0621f8eba169780c592916eeaf2855c69541f4b (diff) | |
| download | rust-5a240588895b733f4e41fb8f9cb0a3d2f80b1e87.tar.gz rust-5a240588895b733f4e41fb8f9cb0a3d2f80b1e87.zip | |
libcollections: remove unnecessary `as_mut_slice()` calls
| -rw-r--r-- | src/libcollections/binary_heap.rs | 2 | ||||
| -rw-r--r-- | src/libcollections/btree/node.rs | 16 | ||||
| -rw-r--r-- | src/libcollections/slice.rs | 34 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 12 |
4 files changed, 32 insertions, 32 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 53d20aab24d..e321ef16f66 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -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() diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index 2c681b6b1d3..3f53bad6518 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -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); diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 57e16fd7454..9417cc3e594 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -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])); } } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e2411ced632..c77ef86697b 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -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) |
