Merge pull request #3077 from erickt/incoming
core: change vec's ref_set to set_ref, move get_ref to unsafe::get.
This commit is contained in:
commit
dc499f193e
1 changed files with 26 additions and 20 deletions
|
@ -189,7 +189,7 @@ pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> ~[T] {
|
||||||
let mut v = ~[];
|
let mut v = ~[];
|
||||||
unchecked{reserve(v, n_elts);}
|
unchecked{reserve(v, n_elts);}
|
||||||
let mut i: uint = 0u;
|
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); }
|
unsafe { unsafe::set_len(v, n_elts); }
|
||||||
ret v;
|
ret v;
|
||||||
}
|
}
|
||||||
|
@ -204,8 +204,8 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
|
||||||
let mut v = ~[];
|
let mut v = ~[];
|
||||||
unchecked{reserve(v, n_elts)}
|
unchecked{reserve(v, n_elts)}
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
unsafe { // because ref_set is unsafe
|
unsafe { // because unsafe::set is unsafe
|
||||||
while i < n_elts { ref_set(v, i, t); i += 1u; }
|
while i < n_elts { unsafe::set(v, i, t); i += 1u; }
|
||||||
unsafe { unsafe::set_len(v, n_elts); }
|
unsafe { unsafe::set_len(v, n_elts); }
|
||||||
}
|
}
|
||||||
ret v;
|
ret v;
|
||||||
|
@ -534,28 +534,12 @@ fn push_slow<T>(&v: ~[const T], +initval: T) {
|
||||||
unsafe { push_fast(v, initval) }
|
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)]
|
#[inline(always)]
|
||||||
fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
|
fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
|
||||||
reserve(v, v.len() + rhs.len());
|
reserve(v, v.len() + rhs.len());
|
||||||
|
|
||||||
for uint::range(0u, rhs.len()) |i| {
|
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 @@ mod unsafe {
|
||||||
f(*v)
|
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.
|
* Copies data from one vector to another.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue