Skip to content

Commit bbc3f96

Browse files
authored
Remove dead cache from IndexSet (#262)
The `IndexSet::cache` field was never populated with a real value, and `cache.set()` was only ever called with the `(INVALID, 0)` sentinel, so the fast-path in `maybe_elem()` was unreachable and the invalidation stores in `elem()` and `maybe_elem_mut()` were pure-overhead on every `set`/`get`/`union_with`. Removing it additionally shrinks `IndexSet` by 16 bytes.
1 parent aa9680b commit bbc3f96

1 file changed

Lines changed: 1 addition & 18 deletions

File tree

‎src/indexset.rs‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66
//! Index sets: sets of integers that represent indices into a space.
77
88
use alloc::vec::Vec;
9-
use core::cell::Cell;
109

1110
use crate::FxHashMap;
1211

1312
const SMALL_ELEMS: usize = 12;
1413

1514
/// A hybrid large/small-mode sparse mapping from integer indices to
1615
/// elements.
17-
///
18-
/// The trailing `(u32, u64)` elements in each variant is a one-item
19-
/// cache to allow fast access when streaming through.
2016
#[derive(Clone, Debug)]
2117
enum AdaptiveMap {
2218
Small {
@@ -182,7 +178,6 @@ impl<'a> core::iter::Iterator for AdaptiveMapIter<'a> {
182178
#[derive(Clone)]
183179
pub struct IndexSet {
184180
elems: AdaptiveMap,
185-
cache: Cell<(u32, u64)>,
186181
}
187182

188183
const BITS_PER_WORD: usize = 64;
@@ -191,36 +186,25 @@ impl IndexSet {
191186
pub fn new() -> Self {
192187
Self {
193188
elems: AdaptiveMap::new(),
194-
cache: Cell::new((INVALID, 0)),
195189
}
196190
}
197191

198192
#[inline(always)]
199193
fn elem(&mut self, bit_index: usize) -> &mut u64 {
200194
let word_index = (bit_index / BITS_PER_WORD) as u32;
201-
if self.cache.get().0 == word_index {
202-
self.cache.set((INVALID, 0));
203-
}
204195
self.elems.get_or_insert(word_index)
205196
}
206197

207198
#[inline(always)]
208199
fn maybe_elem_mut(&mut self, bit_index: usize) -> Option<&mut u64> {
209200
let word_index = (bit_index / BITS_PER_WORD) as u32;
210-
if self.cache.get().0 == word_index {
211-
self.cache.set((INVALID, 0));
212-
}
213201
self.elems.get_mut(word_index)
214202
}
215203

216204
#[inline(always)]
217205
fn maybe_elem(&self, bit_index: usize) -> Option<u64> {
218206
let word_index = (bit_index / BITS_PER_WORD) as u32;
219-
if self.cache.get().0 == word_index {
220-
Some(self.cache.get().1)
221-
} else {
222-
self.elems.get(word_index)
223-
}
207+
self.elems.get(word_index)
224208
}
225209

226210
#[inline(always)]
@@ -235,7 +219,6 @@ impl IndexSet {
235219

236220
pub fn assign(&mut self, other: &Self) {
237221
self.elems = other.elems.clone();
238-
self.cache = other.cache.clone();
239222
}
240223

241224
#[inline(always)]

0 commit comments

Comments
 (0)