parent
032d5c1dcd
commit
d9b2e6b74f
1 changed files with 7 additions and 1 deletions
|
@ -964,7 +964,7 @@ impl<T> Vec<T> {
|
|||
#[inline]
|
||||
pub fn swap_remove(&mut self, index: uint) -> Option<T> {
|
||||
let length = self.len();
|
||||
if index < length - 1 {
|
||||
if length > 0 && index < length - 1 {
|
||||
self.as_mut_slice().swap(index, length - 1);
|
||||
} else if index >= length {
|
||||
return None
|
||||
|
@ -2003,6 +2003,12 @@ mod tests {
|
|||
let _ = vec[3];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_swap_remove_empty() {
|
||||
let mut vec: Vec<uint> = vec!();
|
||||
assert_eq!(vec.swap_remove(0), None);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_new(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue