From 8b385475f64cc4709af2223d6279ba7b23f22269 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 16 Aug 2024 15:11:45 -0700 Subject: [PATCH] review comments --- .../src/semantic_index/use_def/bitset.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/red_knot_python_semantic/src/semantic_index/use_def/bitset.rs b/crates/red_knot_python_semantic/src/semantic_index/use_def/bitset.rs index 45b6dd51bb4a5..ac8ce65398e1b 100644 --- a/crates/red_knot_python_semantic/src/semantic_index/use_def/bitset.rs +++ b/crates/red_knot_python_semantic/src/semantic_index/use_def/bitset.rs @@ -32,8 +32,8 @@ impl BitSet { bitset } - /// Convert from Inline to Heap representation. - fn overflow(&mut self, value: u32) { + /// Convert from Inline to Heap, if needed, and resize the Heap vector, if needed. + fn resize(&mut self, value: u32) { let num_blocks_needed = (value / 64) + 1; match self { Self::Inline(blocks) => { @@ -47,14 +47,14 @@ impl BitSet { } } - fn get_blocks_mut(&mut self) -> &mut [u64] { + fn blocks_mut(&mut self) -> &mut [u64] { match self { Self::Inline(blocks) => blocks.as_mut_slice(), Self::Heap(blocks) => blocks.as_mut_slice(), } } - fn get_blocks(&self) -> &[u64] { + fn blocks(&self) -> &[u64] { match self { Self::Inline(blocks) => blocks.as_slice(), Self::Heap(blocks) => blocks.as_slice(), @@ -67,10 +67,10 @@ impl BitSet { pub(super) fn insert(&mut self, value: u32) -> bool { let value_usize = value as usize; let (block, index) = (value_usize / 64, value_usize % 64); - if block >= self.get_blocks().len() { - self.overflow(value); + if block >= self.blocks().len() { + self.resize(value); } - let blocks = self.get_blocks_mut(); + let blocks = self.blocks_mut(); let missing = blocks[block] & (1 << index) == 0; blocks[block] |= 1 << index; missing @@ -78,8 +78,8 @@ impl BitSet { /// Intersect in-place with another [`BitSet`]. pub(super) fn intersect(&mut self, other: &BitSet) { - let my_blocks = self.get_blocks_mut(); - let other_blocks = other.get_blocks(); + let my_blocks = self.blocks_mut(); + let other_blocks = other.blocks(); let min_len = my_blocks.len().min(other_blocks.len()); for i in 0..min_len { my_blocks[i] &= other_blocks[i]; @@ -91,7 +91,7 @@ impl BitSet { /// Return an iterator over the values (in ascending order) in this [`BitSet`]. pub(super) fn iter(&self) -> BitSetIterator<'_, B> { - let blocks = self.get_blocks(); + let blocks = self.blocks(); BitSetIterator { blocks, current_block_index: 0,