vec: replace some as_mut_buf with to_mut_ptr

This commit is contained in:
Daniel Micay 2013-07-27 17:30:29 -04:00
parent 7ae17e0964
commit ffe549daf5

View File

@ -49,13 +49,12 @@ pub fn same_length<T, U>(xs: &[T], ys: &[U]) -> bool {
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T] {
unsafe {
let mut v = with_capacity(n_elts);
do v.as_mut_buf |p, _len| {
let p = raw::to_mut_ptr(v);
let mut i: uint = 0u;
while i < n_elts {
intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i)), op(i));
i += 1u;
}
}
raw::set_len(&mut v, n_elts);
v
}
@ -74,13 +73,12 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] {
// vec::with_capacity/ptr::set_memory for primitive types.
unsafe {
let mut v = with_capacity(n_elts);
do v.as_mut_buf |p, _len| {
let p = raw::to_mut_ptr(v);
let mut i = 0u;
while i < n_elts {
intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i)), t.clone());
i += 1u;
}
}
raw::set_len(&mut v, n_elts);
v
}