Skip to content
Snippets Groups Projects
Commit 4d7d1eaa authored by Shawn Tabrizi's avatar Shawn Tabrizi Committed by GitHub
Browse files

dont increase the allocated size of vec (#10701)

parent 362a6d9b
No related merge requests found
......@@ -222,16 +222,17 @@ impl<T, S: Get<u32>> BoundedVec<T, S> {
/// Returns `true` if the item was inserted.
pub fn force_insert_keep_left(&mut self, index: usize, element: T) -> bool {
// Check against panics.
if Self::bound() < index || self.len() < index {
if Self::bound() < index || self.len() < index || Self::bound() == 0 {
return false
}
// Noop condition.
if Self::bound() == index && self.len() <= Self::bound() {
return false
}
// Cannot panic since self.len() >= index;
// Cannot panic since `Self.bound() > 0`
self.0.truncate(Self::bound() - 1);
// Cannot panic since `self.len() >= index`;
self.0.insert(index, element);
self.0.truncate(Self::bound());
true
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment