Skip to content

Remove unnecessary check in VecDeque::grow #91339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2179,19 +2179,21 @@ impl<T, A: Allocator> VecDeque<T, A> {
}
}

// Double the buffer size. This method is inline(never), so we expect it to only
// be called in cold paths.
// This may panic or abort
#[inline(never)]
fn grow(&mut self) {
if self.is_full() {
let old_cap = self.cap();
// Double the buffer size.
self.buf.reserve_exact(old_cap, old_cap);
assert!(self.cap() == old_cap * 2);
unsafe {
self.handle_capacity_increase(old_cap);
}
debug_assert!(!self.is_full());
// Extend or possibly remove this assertion when valid use-cases for growing the
// buffer without it being full emerge
debug_assert!(self.is_full());
let old_cap = self.cap();
self.buf.reserve_exact(old_cap, old_cap);
assert!(self.cap() == old_cap * 2);
unsafe {
self.handle_capacity_increase(old_cap);
}
debug_assert!(!self.is_full());
}

/// Modifies the `VecDeque` in-place so that `len()` is equal to `new_len`,
Expand Down