File tree 1 file changed +4
-13
lines changed
1 file changed +4
-13
lines changed Original file line number Diff line number Diff line change @@ -294,27 +294,18 @@ fn shift<T: copy>(&v: [const T]) -> T {
294
294
ret e;
295
295
}
296
296
297
- // TODO: Write this, unsafely, in a way that's not O(n).
298
297
/*
299
298
Function: pop
300
299
301
300
Remove the last element from a vector and return it
302
301
*/
303
- fn pop < T : copy > ( & v: [ const T ] ) -> T {
302
+ fn pop< T > ( & v: [ const T ] ) -> T unsafe {
304
303
let ln = len ( v) ;
305
- assert ( ln > 0 u) ;
306
- ln -= 1 u;
307
- let e = v[ ln] ;
308
- v = slice ( v, 0 u, ln) ;
309
- ret e;
310
- // FIXME use this implementation after the next snapshot (27.01.2012)
311
- /* let new_ln = len(v) - 1u;
312
- assert (new_ln > 0u);
313
- let valptr = ptr::mut_addr_of(v[new_ln]);
304
+ assert ln > 0 u;
305
+ let valptr = ptr:: mut_addr_of ( v[ ln - 1 u] ) ;
314
306
let val <- * valptr;
315
- unsafe::set_len(v, new_ln );
307
+ unsafe :: set_len ( v , ln - 1 u ) ;
316
308
val
317
- */
318
309
}
319
310
320
311
/*
You can’t perform that action at this time.
0 commit comments