From 4f62c969f618463914b148d53bef1d0faeb2782f Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sun, 15 Dec 2013 22:44:51 +1100 Subject: std::vec: move pointless `raw::get` and `unsafe_get` functions. This can easily be written as `(*v.unsafe_ref(i)).clone()`, or just `*v.unsafe_ref(i)` for primitive types like `i32` (the common case). --- src/libstd/rand/isaac.rs | 8 ++++---- src/libstd/vec.rs | 16 ---------------- 2 files changed, 4 insertions(+), 20 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/rand/isaac.rs b/src/libstd/rand/isaac.rs index 3dcf97212f5..5ba6994b78d 100644 --- a/src/libstd/rand/isaac.rs +++ b/src/libstd/rand/isaac.rs @@ -341,7 +341,7 @@ impl Isaac64Rng { static MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)]; macro_rules! ind ( ($x:expr) => { - self.mem.unsafe_get(($x as uint >> 3) & (RAND_SIZE_64 - 1)) + *self.mem.unsafe_ref(($x as uint >> 3) & (RAND_SIZE_64 - 1)) } ); macro_rules! rngstep( @@ -355,8 +355,8 @@ impl Isaac64Rng { let mix = if $j == 0 {!mix} else {mix}; unsafe { - let x = self.mem.unsafe_get(base + mr_offset); - a = mix + self.mem.unsafe_get(base + m2_offset); + let x = *self.mem.unsafe_ref(base + mr_offset); + a = mix + *self.mem.unsafe_ref(base + m2_offset); let y = ind!(x) + a + b; self.mem.unsafe_set(base + mr_offset, y); @@ -395,7 +395,7 @@ impl Rng for Isaac64Rng { self.isaac64(); } self.cnt -= 1; - unsafe { self.rsl.unsafe_get(self.cnt) } + unsafe { *self.rsl.unsafe_ref(self.cnt) } } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index c14068a7c88..fc051a7e2b5 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1270,8 +1270,6 @@ pub trait ImmutableCopyableVector { * those that do not. */ fn partitioned(&self, f: |&T| -> bool) -> (~[T], ~[T]); - /// Returns the element at the given index, without doing bounds checking. - unsafe fn unsafe_get(&self, elem: uint) -> T; /// Create an iterator that yields every possible permutation of the /// vector in succession. @@ -1295,11 +1293,6 @@ impl<'a,T:Clone> ImmutableCopyableVector for &'a [T] { (lefts, rights) } - #[inline] - unsafe fn unsafe_get(&self, index: uint) -> T { - (*self.unsafe_ref(index)).clone() - } - fn permutations(self) -> Permutations { Permutations{ swaps: ElementSwaps::new(self.len()), @@ -2192,7 +2185,6 @@ pub unsafe fn from_buf(ptr: *T, elts: uint) -> ~[T] { /// Unsafe operations pub mod raw { use cast; - use clone::Clone; use option::Some; use ptr; use mem; @@ -2269,14 +2261,6 @@ pub mod raw { })) } - /** - * Unchecked vector indexing. - */ - #[inline] - pub unsafe fn get(v: &[T], i: uint) -> T { - v.as_imm_buf(|p, _len| (*ptr::offset(p, i as int)).clone()) - } - /** * Unchecked vector index assignment. Does not drop the * old value and hence is only suitable when the vector -- cgit 1.4.1-3-g733a5