From ffe6cdd52d416fc69592baf75567aef41b536445 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 21 May 2026 15:19:22 -0400 Subject: [PATCH] compiler/rust/bitset: Don't reserve space in remove() If the requested bit is past the end of the set, we can just return false. We don't have to grow the bitset. Reviewed-by: Mel Henning Part-of: --- src/compiler/rust/bitset.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/rust/bitset.rs b/src/compiler/rust/bitset.rs index 9fc25c5ef77..204912052b5 100644 --- a/src/compiler/rust/bitset.rs +++ b/src/compiler/rust/bitset.rs @@ -181,10 +181,13 @@ impl BitSet { pub fn remove(&mut self, key: K) -> bool { let idx = BitIndex::from(key); - self.reserve_words(idx.word + 1); - let exists = self.words[idx.word] & (1_u32 << idx.bit) != 0; - self.words[idx.word] &= !(1_u32 << idx.bit); - exists + if idx.word < self.words.len() { + let exists = self.words[idx.word] & (1_u32 << idx.bit) != 0; + self.words[idx.word] &= !(1_u32 << idx.bit); + exists + } else { + false + } } }