Skip to content

Commit

Permalink
chore(*): finalize SCC 2.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
wvwwvwwv committed Feb 1, 2024
1 parent 7b7976d commit 27c29d6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
6 changes: 1 addition & 5 deletions src/hash_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ where
#[inline]
pub fn retain<F: FnMut(&K, &mut V) -> bool>(&self, mut pred: F) {
#[allow(clippy::redundant_closure_for_method_calls)]
self.retain_entries(|k, v| pred(k, v), |l, e| l.remove_from_lru_list(e));
self.retain_entries(|k, v| pred(k, v));
}

/// Retains the entries specified by the predicate.
Expand Down Expand Up @@ -913,7 +913,6 @@ where
while entry_ptr.next(&locker, &guard) {
let (k, v) = entry_ptr.get_mut(data_block_mut, &mut locker);
if !filter(k, v) {
locker.remove_from_lru_list(&entry_ptr);
locker.erase(data_block_mut, &entry_ptr);
removed = true;
}
Expand Down Expand Up @@ -1461,9 +1460,6 @@ where
#[must_use]
pub fn remove_entry(mut self) -> (K, V) {
let (k, v) = unsafe {
self.locked_entry
.locker
.remove_from_lru_list(&self.locked_entry.entry_ptr);
self.locked_entry
.locker
.erase(
Expand Down
2 changes: 1 addition & 1 deletion src/hash_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ where
/// ```
#[inline]
pub fn retain<F: FnMut(&K, &V) -> bool>(&self, mut pred: F) {
self.retain_entries(|k, v| pred(k, v), |_, _| ());
self.retain_entries(|k, v| pred(k, v));
}

/// Retains the entries specified by the predicate.
Expand Down
2 changes: 1 addition & 1 deletion src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ where
/// ```
#[inline]
pub fn retain<F: FnMut(&K, &mut V) -> bool>(&self, pred: F) {
self.retain_entries(pred, |_, _| ());
self.retain_entries(pred);
}

/// Retains the entries specified by the predicate.
Expand Down
10 changes: 1 addition & 9 deletions src/hash_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,7 @@ where

/// Retains entries that satisfy the specified predicate.
#[inline]
fn retain_entries<
F: FnMut(&K, &mut V) -> bool,
E: Fn(&mut Locker<K, V, L, TYPE>, &EntryPtr<K, V, TYPE>),
>(
&self,
mut pred: F,
erase_callback: E,
) {
fn retain_entries<F: FnMut(&K, &mut V) -> bool>(&self, mut pred: F) {
let guard = Guard::new();
let mut removed = false;
let mut current_array_ptr = self.bucket_array().load(Acquire, &guard);
Expand All @@ -534,7 +527,6 @@ where
while entry_ptr.next(&locker, &guard) {
let (k, v) = entry_ptr.get_mut(data_block_mut, &mut locker);
if !pred(k, v) {
erase_callback(&mut locker, &entry_ptr);
locker.erase(data_block_mut, &entry_ptr);
removed = true;
}
Expand Down
16 changes: 10 additions & 6 deletions src/hash_table/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ impl<'g, K: Eq, V, L: LruList, const TYPE: char> Locker<'g, K, V, L, TYPE> {
) -> Option<(K, V)> {
debug_assert_ne!(entry_ptr.current_index, usize::MAX);

if TYPE == CACHE {
self.remove_from_lru_list(entry_ptr);
}

self.bucket.num_entries -= 1;
let link_ptr = entry_ptr.current_link_ptr.as_ptr().cast_mut();
if let Some(link_mut) = unsafe { link_ptr.as_mut() } {
Expand Down Expand Up @@ -856,28 +860,28 @@ impl<'g, K: Eq, V, L: LruList, const TYPE: char> Locker<'g, K, V, L, TYPE> {
None
}

/// Removes the entry from the LRU linked list.
pub(crate) fn remove_from_lru_list(&mut self, entry_ptr: &EntryPtr<K, V, CACHE>) {
/// Sets the entry having been just accessed.
pub(crate) fn update_lru_tail(&mut self, entry_ptr: &EntryPtr<K, V, TYPE>) {
debug_assert_eq!(TYPE, CACHE);
debug_assert!(self.metadata.link.is_null(Relaxed));

#[allow(clippy::cast_possible_truncation)]
let entry = entry_ptr.current_index as u8;
let tail = self.metadata.removed_bitmap_or_lru_tail;
if let Some(new_tail) = self.lru_list.remove(tail, entry) {
if let Some(new_tail) = self.lru_list.promote(tail, entry) {
self.metadata.removed_bitmap_or_lru_tail = new_tail;
}
}

/// Sets the entry having been just accessed.
pub(crate) fn update_lru_tail(&mut self, entry_ptr: &EntryPtr<K, V, CACHE>) {
/// Removes the entry from the LRU linked list.
fn remove_from_lru_list(&mut self, entry_ptr: &EntryPtr<K, V, TYPE>) {
debug_assert_eq!(TYPE, CACHE);
debug_assert!(self.metadata.link.is_null(Relaxed));

#[allow(clippy::cast_possible_truncation)]
let entry = entry_ptr.current_index as u8;
let tail = self.metadata.removed_bitmap_or_lru_tail;
if let Some(new_tail) = self.lru_list.promote(tail, entry) {
if let Some(new_tail) = self.lru_list.remove(tail, entry) {
self.metadata.removed_bitmap_or_lru_tail = new_tail;
}
}
Expand Down

0 comments on commit 27c29d6

Please sign in to comment.