提交 71927615 编写于 作者: E Erick Tryzelaar

core: change vec's ref_set to set_ref, move get_ref to unsafe::get.

上级 357920a0
......@@ -189,7 +189,7 @@ fn reserve_at_least<T>(&v: ~[const T], n: uint) {
let mut v = ~[];
unchecked{reserve(v, n_elts);}
let mut i: uint = 0u;
while i < n_elts unsafe { ref_set(v, i, op(i)); i += 1u; }
while i < n_elts unsafe { unsafe::set(v, i, op(i)); i += 1u; }
unsafe { unsafe::set_len(v, n_elts); }
ret v;
}
......@@ -204,8 +204,8 @@ fn reserve_at_least<T>(&v: ~[const T], n: uint) {
let mut v = ~[];
unchecked{reserve(v, n_elts)}
let mut i: uint = 0u;
unsafe { // because ref_set is unsafe
while i < n_elts { ref_set(v, i, t); i += 1u; }
unsafe { // because unsafe::set is unsafe
while i < n_elts { unsafe::set(v, i, t); i += 1u; }
unsafe { unsafe::set_len(v, n_elts); }
}
ret v;
......@@ -534,28 +534,12 @@ fn push_slow<T>(&v: ~[const T], +initval: T) {
unsafe { push_fast(v, initval) }
}
// Unchecked vector indexing
#[inline(always)]
unsafe fn get_ref<T: copy>(v: &[const T], i: uint) -> T {
as_buf(v, |p, _len| *ptr::offset(p, i))
}
#[inline(always)]
unsafe fn ref_set<T>(v: &[mut T], i: uint, +val: T) {
let mut box = some(val);
do as_mut_buf(v) |p, _len| {
let mut box2 = none;
box2 <-> box;
rusti::move_val_init(*ptr::mut_offset(p, i), option::unwrap(box2));
}
}
#[inline(always)]
fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
reserve(v, v.len() + rhs.len());
for uint::range(0u, rhs.len()) |i| {
push(v, unsafe { get_ref(rhs, i) })
push(v, unsafe { unsafe::get(rhs, i) })
}
}
......@@ -1611,6 +1595,28 @@ unsafe fn form_slice<T,U>(p: *T, len: uint, f: fn(&& &[T]) -> U) -> U {
f(*v)
}
/**
* Unchecked vector indexing.
*/
#[inline(always)]
unsafe fn get<T: copy>(v: &[const T], i: uint) -> T {
as_buf(v, |p, _len| *ptr::offset(p, i))
}
/**
* Unchecked vector index assignment.
*/
#[inline(always)]
unsafe fn set<T>(v: &[mut T], i: uint, +val: T) {
let mut box = some(val);
do as_mut_buf(v) |p, _len| {
let mut box2 = none;
box2 <-> box;
rusti::move_val_init(*ptr::mut_offset(p, i),
option::unwrap(box2));
}
}
/**
* Copies data from one vector to another.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册