From 04680c8b7cc32c41335509d4f82fb916abbf0530 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Mon, 16 Dec 2024 14:27:23 +0100 Subject: [PATCH] fixing an incredible edge case this basically only happens if the Vc oscilates between 7 and 8 elemenst Signed-off-by: Jakub Doka --- lang/src/utils.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lang/src/utils.rs b/lang/src/utils.rs index 3f069a29..86db0dd3 100644 --- a/lang/src/utils.rs +++ b/lang/src/utils.rs @@ -381,25 +381,26 @@ impl Vc { } pub fn push(&mut self, value: Nid) { - if let Some(layout) = self.layout() - && unsafe { self.alloced.len == self.alloced.cap } - { - unsafe { - self.alloced.cap *= 2; - self.alloced.base = Unique::new_unchecked( - alloc::realloc( - self.alloced.base.as_ptr().cast(), - layout, - self.alloced.cap as usize * core::mem::size_of::(), - ) - .cast(), - ); + if let Some(layout) = self.layout() { + if unsafe { self.alloced.len == self.alloced.cap } { + unsafe { + self.alloced.cap *= 2; + self.alloced.base = Unique::new_unchecked( + alloc::realloc( + self.alloced.base.as_ptr().cast(), + layout, + self.alloced.cap as usize * core::mem::size_of::(), + ) + .cast(), + ); + } } } else if self.len() == INLINE_ELEMS { unsafe { let mut allcd = Self::alloc((self.inline.cap + 1).next_power_of_two() as _, self.len()); core::ptr::copy_nonoverlapping(self.as_ptr(), allcd.as_mut_ptr(), self.len()); + debug_assert!(!allcd.is_inline()); *self = allcd; } }