Fix bug in StaticVec.
This commit is contained in:
parent
703cc414b8
commit
e33760a7d4
29
src/utils.rs
29
src/utils.rs
@ -356,10 +356,13 @@ impl<T> StaticVec<T> {
|
|||||||
panic!("nothing to pop!");
|
panic!("nothing to pop!");
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = if self.is_fixed_storage() {
|
if self.is_fixed_storage() {
|
||||||
self.extract_from_list(self.len - 1)
|
let value = self.extract_from_list(self.len - 1);
|
||||||
|
self.len -= 1;
|
||||||
|
value
|
||||||
} else {
|
} else {
|
||||||
let value = self.more.pop().unwrap();
|
let value = self.more.pop().unwrap();
|
||||||
|
self.len -= 1;
|
||||||
|
|
||||||
// Move back to the fixed list
|
// Move back to the fixed list
|
||||||
if self.more.len() == MAX_STATIC_VEC {
|
if self.more.len() == MAX_STATIC_VEC {
|
||||||
@ -370,11 +373,7 @@ impl<T> StaticVec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
value
|
value
|
||||||
};
|
}
|
||||||
|
|
||||||
self.len -= 1;
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
/// Remove a value from this `StaticVec` at a particular position.
|
/// Remove a value from this `StaticVec` at a particular position.
|
||||||
///
|
///
|
||||||
@ -386,18 +385,20 @@ impl<T> StaticVec<T> {
|
|||||||
panic!("index OOB in StaticVec");
|
panic!("index OOB in StaticVec");
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = if self.is_fixed_storage() {
|
if self.is_fixed_storage() {
|
||||||
let value = self.extract_from_list(index);
|
let value = self.extract_from_list(index);
|
||||||
|
|
||||||
// Move all items one slot to the left
|
// Move all items one slot to the left
|
||||||
for x in index..self.len - 1 {
|
for x in index + 1..self.len - 1 {
|
||||||
let orig_value = self.extract_from_list(x + 1);
|
let orig_value = self.extract_from_list(x);
|
||||||
self.set_into_list(x, orig_value, false);
|
self.set_into_list(x - 1, orig_value, false);
|
||||||
}
|
}
|
||||||
|
self.len -= 1;
|
||||||
|
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
let value = self.more.remove(index);
|
let value = self.more.remove(index);
|
||||||
|
self.len -= 1;
|
||||||
|
|
||||||
// Move back to the fixed list
|
// Move back to the fixed list
|
||||||
if self.more.len() == MAX_STATIC_VEC {
|
if self.more.len() == MAX_STATIC_VEC {
|
||||||
@ -408,11 +409,7 @@ impl<T> StaticVec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
value
|
value
|
||||||
};
|
}
|
||||||
|
|
||||||
self.len -= 1;
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
/// Get the number of items in this `StaticVec`.
|
/// Get the number of items in this `StaticVec`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
Loading…
Reference in New Issue
Block a user