diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 4dabab99c238..357df699f877 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -294,27 +294,18 @@ fn shift(&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(&v: [const T]) -> T { +fn pop(&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 -*/ } /*