Skip to content

Commit 7ff159c

Browse files
committed
chore(hash*): minor optimization
1 parent 9a679a0 commit 7ff159c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/hash_table/bucket.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl<K: Eq, V, L: LruList, const TYPE: char> Bucket<K, V, L, TYPE> {
552552
/// Returns `None` if the key is not present.
553553
#[inline]
554554
pub(super) fn search_entry<'g, Q>(
555-
&'g self,
555+
&self,
556556
data_block: &'g DataBlock<K, V, BUCKET_LEN>,
557557
key: &Q,
558558
partial_hash: u8,
@@ -565,18 +565,18 @@ impl<K: Eq, V, L: LruList, const TYPE: char> Bucket<K, V, L, TYPE> {
565565
return None;
566566
}
567567

568-
if let Some((_, entry_ref)) =
568+
if let Some((entry, _)) =
569569
Self::search_data_block(&self.metadata, data_block, key, partial_hash)
570570
{
571-
return Some(entry_ref);
571+
return Some(entry);
572572
}
573573

574574
let mut link_ptr = self.metadata.link.load(Acquire, guard);
575575
while let Some(link) = link_ptr.as_ref() {
576-
if let Some((_, entry_ref)) =
576+
if let Some((entry, _)) =
577577
Self::search_data_block(&link.metadata, &link.data_block, key, partial_hash)
578578
{
579-
return Some(entry_ref);
579+
return Some(entry);
580580
}
581581
link_ptr = link.metadata.link.load(Acquire, guard);
582582
}
@@ -602,7 +602,7 @@ impl<K: Eq, V, L: LruList, const TYPE: char> Bucket<K, V, L, TYPE> {
602602
return EntryPtr::new(guard);
603603
}
604604

605-
if let Some((index, _)) =
605+
if let Some((_, index)) =
606606
Self::search_data_block(&self.metadata, data_block, key, partial_hash)
607607
{
608608
return EntryPtr {
@@ -613,7 +613,7 @@ impl<K: Eq, V, L: LruList, const TYPE: char> Bucket<K, V, L, TYPE> {
613613

614614
let mut current_link_ptr = self.metadata.link.load(Acquire, guard);
615615
while let Some(link) = current_link_ptr.as_ref() {
616-
if let Some((index, _)) =
616+
if let Some((_, index)) =
617617
Self::search_data_block(&link.metadata, &link.data_block, key, partial_hash)
618618
{
619619
return EntryPtr {
@@ -628,12 +628,14 @@ impl<K: Eq, V, L: LruList, const TYPE: char> Bucket<K, V, L, TYPE> {
628628
}
629629

630630
/// Searches the supplied data block for an entry matching the key.
631+
#[allow(clippy::inline_always)]
632+
#[inline(always)]
631633
fn search_data_block<'g, Q, const LEN: usize>(
632-
metadata: &'g Metadata<K, V, LEN>,
634+
metadata: &Metadata<K, V, LEN>,
633635
data_block: &'g DataBlock<K, V, LEN>,
634636
key: &Q,
635637
partial_hash: u8,
636-
) -> Option<(usize, &'g (K, V))>
638+
) -> Option<(&'g (K, V), usize)>
637639
where
638640
Q: Equivalent<K> + ?Sized,
639641
{
@@ -657,9 +659,9 @@ impl<K: Eq, V, L: LruList, const TYPE: char> Bucket<K, V, L, TYPE> {
657659

658660
let mut offset = bitmap.trailing_zeros();
659661
while offset != u32::BITS {
660-
let entry_ref = unsafe { &(*data_block[offset as usize].as_ptr()) };
661-
if key.equivalent(&entry_ref.0) {
662-
return Some((offset as usize, entry_ref));
662+
let entry = unsafe { &(*data_block[offset as usize].as_ptr()) };
663+
if key.equivalent(&entry.0) {
664+
return Some((entry, offset as usize));
663665
}
664666
bitmap -= 1_u32 << offset;
665667
offset = bitmap.trailing_zeros();

0 commit comments

Comments
 (0)