std -- replaces uses where const borrows would be required
This commit is contained in:
parent
be3cbcb431
commit
852a49fd9c
3 changed files with 125 additions and 70 deletions
|
@ -119,7 +119,8 @@ use mem;
|
|||
use mem::size_of;
|
||||
use kinds::marker;
|
||||
use uint;
|
||||
use unstable::finally::Finally;
|
||||
use unstable::finally::try_finally;
|
||||
use unstable::intrinsics;
|
||||
use unstable::raw::{Repr, Slice, Vec};
|
||||
|
||||
/**
|
||||
|
@ -132,15 +133,16 @@ pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> ~[T] {
|
|||
unsafe {
|
||||
let mut v = with_capacity(n_elts);
|
||||
let p = v.as_mut_ptr();
|
||||
let mut i: uint = 0u;
|
||||
(|| {
|
||||
while i < n_elts {
|
||||
mem::move_val_init(&mut(*ptr::mut_offset(p, i as int)), op(i));
|
||||
i += 1u;
|
||||
}
|
||||
}).finally(|| {
|
||||
v.set_len(i);
|
||||
});
|
||||
let mut i = 0;
|
||||
try_finally(
|
||||
&mut i, (),
|
||||
|i, ()| while *i < n_elts {
|
||||
mem::move_val_init(
|
||||
&mut(*ptr::mut_offset(p, *i as int)),
|
||||
op(*i));
|
||||
*i += 1u;
|
||||
},
|
||||
|i| v.set_len(*i));
|
||||
v
|
||||
}
|
||||
}
|
||||
|
@ -160,14 +162,15 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] {
|
|||
let mut v = with_capacity(n_elts);
|
||||
let p = v.as_mut_ptr();
|
||||
let mut i = 0u;
|
||||
(|| {
|
||||
while i < n_elts {
|
||||
mem::move_val_init(&mut(*ptr::mut_offset(p, i as int)), t.clone());
|
||||
i += 1u;
|
||||
}
|
||||
}).finally(|| {
|
||||
v.set_len(i);
|
||||
});
|
||||
try_finally(
|
||||
&mut i, (),
|
||||
|i, ()| while *i < n_elts {
|
||||
mem::move_val_init(
|
||||
&mut(*ptr::mut_offset(p, *i as int)),
|
||||
t.clone());
|
||||
*i += 1u;
|
||||
},
|
||||
|i| v.set_len(*i));
|
||||
v
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue