vec: replace some as_mut_buf
with to_mut_ptr
This commit is contained in:
parent
7ae17e0964
commit
ffe549daf5
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user