X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Falloc%2Fsrc%2Fcollections%2Fvec_deque%2Fmod.rs;h=061e2758e49855cf5798800440cecca62a6ac925;hb=6fd5cf51c1528c16f8a186ced5d6d21b1d70e319;hp=de607c8fdab31dd098a5ee88c1f76dd81f41ac85;hpb=327d8073e2a7939e12676940fc4847ca78be3f84;p=rust.git diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index de607c8fdab..061e2758e49 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2179,19 +2179,21 @@ pub fn retain(&mut self, mut f: F) } } + // 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`, @@ -3016,6 +3018,8 @@ fn from(mut other: VecDeque) -> Self { #[stable(feature = "std_collections_from_array", since = "1.56.0")] impl From<[T; N]> for VecDeque { + /// Converts a `[T; N]` into a `VecDeque`. + /// /// ``` /// use std::collections::VecDeque; ///