Skip to content

Commit 4f62c96

Browse files
committed
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).
1 parent 0393c40 commit 4f62c96

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

src/libstd/rand/isaac.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl Isaac64Rng {
341341
static MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)];
342342
macro_rules! ind (
343343
($x:expr) => {
344-
self.mem.unsafe_get(($x as uint >> 3) & (RAND_SIZE_64 - 1))
344+
*self.mem.unsafe_ref(($x as uint >> 3) & (RAND_SIZE_64 - 1))
345345
}
346346
);
347347
macro_rules! rngstep(
@@ -355,8 +355,8 @@ impl Isaac64Rng {
355355
let mix = if $j == 0 {!mix} else {mix};
356356

357357
unsafe {
358-
let x = self.mem.unsafe_get(base + mr_offset);
359-
a = mix + self.mem.unsafe_get(base + m2_offset);
358+
let x = *self.mem.unsafe_ref(base + mr_offset);
359+
a = mix + *self.mem.unsafe_ref(base + m2_offset);
360360
let y = ind!(x) + a + b;
361361
self.mem.unsafe_set(base + mr_offset, y);
362362

@@ -395,7 +395,7 @@ impl Rng for Isaac64Rng {
395395
self.isaac64();
396396
}
397397
self.cnt -= 1;
398-
unsafe { self.rsl.unsafe_get(self.cnt) }
398+
unsafe { *self.rsl.unsafe_ref(self.cnt) }
399399
}
400400
}
401401

src/libstd/vec.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,6 @@ pub trait ImmutableCopyableVector<T> {
12701270
* those that do not.
12711271
*/
12721272
fn partitioned(&self, f: |&T| -> bool) -> (~[T], ~[T]);
1273-
/// Returns the element at the given index, without doing bounds checking.
1274-
unsafe fn unsafe_get(&self, elem: uint) -> T;
12751273

12761274
/// Create an iterator that yields every possible permutation of the
12771275
/// vector in succession.
@@ -1295,11 +1293,6 @@ impl<'a,T:Clone> ImmutableCopyableVector<T> for &'a [T] {
12951293
(lefts, rights)
12961294
}
12971295

1298-
#[inline]
1299-
unsafe fn unsafe_get(&self, index: uint) -> T {
1300-
(*self.unsafe_ref(index)).clone()
1301-
}
1302-
13031296
fn permutations(self) -> Permutations<T> {
13041297
Permutations{
13051298
swaps: ElementSwaps::new(self.len()),
@@ -2192,7 +2185,6 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
21922185
/// Unsafe operations
21932186
pub mod raw {
21942187
use cast;
2195-
use clone::Clone;
21962188
use option::Some;
21972189
use ptr;
21982190
use mem;
@@ -2269,14 +2261,6 @@ pub mod raw {
22692261
}))
22702262
}
22712263

2272-
/**
2273-
* Unchecked vector indexing.
2274-
*/
2275-
#[inline]
2276-
pub unsafe fn get<T:Clone>(v: &[T], i: uint) -> T {
2277-
v.as_imm_buf(|p, _len| (*ptr::offset(p, i as int)).clone())
2278-
}
2279-
22802264
/**
22812265
* Unchecked vector index assignment. Does not drop the
22822266
* old value and hence is only suitable when the vector

src/test/bench/shootout-fannkuch-redux.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ fn fannkuch_redux(n: i32) -> i32 {
3737
let mut flips_count: i32 = 0;
3838
let mut k: i32;
3939
loop {
40-
k = perm.unsafe_get(0);
40+
k = *perm.unsafe_ref(0);
4141
if k == 0 {
4242
break;
4343
}
4444

4545
let k2 = (k+1) >> 1;
4646
for i in range(0i32, k2) {
4747
let (perm_i, perm_k_i) = {
48-
(perm.unsafe_get(i as uint),
49-
perm.unsafe_get((k-i) as uint))
48+
(*perm.unsafe_ref(i as uint),
49+
*perm.unsafe_ref((k-i) as uint))
5050
};
5151
perm.unsafe_set(i as uint, perm_k_i);
5252
perm.unsafe_set((k-i) as uint, perm_i);
@@ -72,15 +72,15 @@ fn fannkuch_redux(n: i32) -> i32 {
7272
let mut i: i32 = 0;
7373
while i < r {
7474
let j = i + 1;
75-
let perm1_j = { perm1.unsafe_get(j as uint) };
75+
let perm1_j = { *perm1.unsafe_ref(j as uint) };
7676
perm1.unsafe_set(i as uint, perm1_j);
7777
i = j;
7878
}
7979
perm1.unsafe_set(r as uint, perm0);
8080

81-
let count_r = { count.unsafe_get(r as uint) };
81+
let count_r = { *count.unsafe_ref(r as uint) };
8282
count.unsafe_set(r as uint, count_r - 1);
83-
if count.unsafe_get(r as uint) > 0 {
83+
if *count.unsafe_ref(r as uint) > 0 {
8484
break;
8585
}
8686
r += 1;

0 commit comments

Comments
 (0)