diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-15 22:44:51 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-15 23:05:00 +1100 |
| commit | 4f62c969f618463914b148d53bef1d0faeb2782f (patch) | |
| tree | 3a6a4bfd063c9b9caf606aff7ad0a409399897d1 | |
| parent | 0393c402a6f523993bb47c579d7382bec507bde7 (diff) | |
| download | rust-4f62c969f618463914b148d53bef1d0faeb2782f.tar.gz rust-4f62c969f618463914b148d53bef1d0faeb2782f.zip | |
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).
| -rw-r--r-- | src/libstd/rand/isaac.rs | 8 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 16 | ||||
| -rw-r--r-- | src/test/bench/shootout-fannkuch-redux.rs | 12 |
3 files changed, 10 insertions, 26 deletions
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<T> { * 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<T> for &'a [T] { (lefts, rights) } - #[inline] - unsafe fn unsafe_get(&self, index: uint) -> T { - (*self.unsafe_ref(index)).clone() - } - fn permutations(self) -> Permutations<T> { Permutations{ swaps: ElementSwaps::new(self.len()), @@ -2192,7 +2185,6 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] { /// Unsafe operations pub mod raw { use cast; - use clone::Clone; use option::Some; use ptr; use mem; @@ -2270,14 +2262,6 @@ pub mod raw { } /** - * Unchecked vector indexing. - */ - #[inline] - pub unsafe fn get<T:Clone>(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 * is newly allocated. diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 079ec7c50bb..ea57eae22b8 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -37,7 +37,7 @@ fn fannkuch_redux(n: i32) -> i32 { let mut flips_count: i32 = 0; let mut k: i32; loop { - k = perm.unsafe_get(0); + k = *perm.unsafe_ref(0); if k == 0 { break; } @@ -45,8 +45,8 @@ fn fannkuch_redux(n: i32) -> i32 { let k2 = (k+1) >> 1; for i in range(0i32, k2) { let (perm_i, perm_k_i) = { - (perm.unsafe_get(i as uint), - perm.unsafe_get((k-i) as uint)) + (*perm.unsafe_ref(i as uint), + *perm.unsafe_ref((k-i) as uint)) }; perm.unsafe_set(i as uint, perm_k_i); perm.unsafe_set((k-i) as uint, perm_i); @@ -72,15 +72,15 @@ fn fannkuch_redux(n: i32) -> i32 { let mut i: i32 = 0; while i < r { let j = i + 1; - let perm1_j = { perm1.unsafe_get(j as uint) }; + let perm1_j = { *perm1.unsafe_ref(j as uint) }; perm1.unsafe_set(i as uint, perm1_j); i = j; } perm1.unsafe_set(r as uint, perm0); - let count_r = { count.unsafe_get(r as uint) }; + let count_r = { *count.unsafe_ref(r as uint) }; count.unsafe_set(r as uint, count_r - 1); - if count.unsafe_get(r as uint) > 0 { + if *count.unsafe_ref(r as uint) > 0 { break; } r += 1; |
