提交 694de53d 编写于 作者: M Marijn Haverbeke

Make vec::pop efficient

上级 2dbaa05a
......@@ -294,27 +294,18 @@ fn shift<T: copy>(&v: [const T]) -> T {
ret e;
}
// TODO: Write this, unsafely, in a way that's not O(n).
/*
Function: pop
Remove the last element from a vector and return it
*/
fn pop<T: copy>(&v: [const T]) -> T {
fn pop<T>(&v: [const T]) -> T unsafe {
let ln = len(v);
assert (ln > 0u);
ln -= 1u;
let e = v[ln];
v = slice(v, 0u, ln);
ret e;
// FIXME use this implementation after the next snapshot (27.01.2012)
/* let new_ln = len(v) - 1u;
assert (new_ln > 0u);
let valptr = ptr::mut_addr_of(v[new_ln]);
assert ln > 0u;
let valptr = ptr::mut_addr_of(v[ln - 1u]);
let val <- *valptr;
unsafe::set_len(v, new_ln);
unsafe::set_len(v, ln - 1u);
val
*/
}
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册