Skip to content

Commit dc499f1

Browse files
committed
Merge pull request #3077 from erickt/incoming
core: change vec's ref_set to set_ref, move get_ref to unsafe::get.
2 parents ba82240 + 7192761 commit dc499f1

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/libcore/vec.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> ~[T] {
189189
let mut v = ~[];
190190
unchecked{reserve(v, n_elts);}
191191
let mut i: uint = 0u;
192-
while i < n_elts unsafe { ref_set(v, i, op(i)); i += 1u; }
192+
while i < n_elts unsafe { unsafe::set(v, i, op(i)); i += 1u; }
193193
unsafe { unsafe::set_len(v, n_elts); }
194194
ret v;
195195
}
@@ -204,8 +204,8 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
204204
let mut v = ~[];
205205
unchecked{reserve(v, n_elts)}
206206
let mut i: uint = 0u;
207-
unsafe { // because ref_set is unsafe
208-
while i < n_elts { ref_set(v, i, t); i += 1u; }
207+
unsafe { // because unsafe::set is unsafe
208+
while i < n_elts { unsafe::set(v, i, t); i += 1u; }
209209
unsafe { unsafe::set_len(v, n_elts); }
210210
}
211211
ret v;
@@ -534,28 +534,12 @@ fn push_slow<T>(&v: ~[const T], +initval: T) {
534534
unsafe { push_fast(v, initval) }
535535
}
536536

537-
// Unchecked vector indexing
538-
#[inline(always)]
539-
unsafe fn get_ref<T: copy>(v: &[const T], i: uint) -> T {
540-
as_buf(v, |p, _len| *ptr::offset(p, i))
541-
}
542-
543-
#[inline(always)]
544-
unsafe fn ref_set<T>(v: &[mut T], i: uint, +val: T) {
545-
let mut box = some(val);
546-
do as_mut_buf(v) |p, _len| {
547-
let mut box2 = none;
548-
box2 <-> box;
549-
rusti::move_val_init(*ptr::mut_offset(p, i), option::unwrap(box2));
550-
}
551-
}
552-
553537
#[inline(always)]
554538
fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
555539
reserve(v, v.len() + rhs.len());
556540

557541
for uint::range(0u, rhs.len()) |i| {
558-
push(v, unsafe { get_ref(rhs, i) })
542+
push(v, unsafe { unsafe::get(rhs, i) })
559543
}
560544
}
561545

@@ -1611,6 +1595,28 @@ mod unsafe {
16111595
f(*v)
16121596
}
16131597

1598+
/**
1599+
* Unchecked vector indexing.
1600+
*/
1601+
#[inline(always)]
1602+
unsafe fn get<T: copy>(v: &[const T], i: uint) -> T {
1603+
as_buf(v, |p, _len| *ptr::offset(p, i))
1604+
}
1605+
1606+
/**
1607+
* Unchecked vector index assignment.
1608+
*/
1609+
#[inline(always)]
1610+
unsafe fn set<T>(v: &[mut T], i: uint, +val: T) {
1611+
let mut box = some(val);
1612+
do as_mut_buf(v) |p, _len| {
1613+
let mut box2 = none;
1614+
box2 <-> box;
1615+
rusti::move_val_init(*ptr::mut_offset(p, i),
1616+
option::unwrap(box2));
1617+
}
1618+
}
1619+
16141620
/**
16151621
* Copies data from one vector to another.
16161622
*

0 commit comments

Comments
 (0)