Skip to content

Commit 44fa31d

Browse files
authored
Merge pull request #607 from ldm0/ldm_optimize
Skip `match_empty` after failed to find a insert slot in group
2 parents 1d16814 + d021052 commit 44fa31d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/raw/mod.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,18 +1718,20 @@ impl RawTableInner {
17181718
insert_slot = self.find_insert_slot_in_group(&group, &probe_seq);
17191719
}
17201720

1721-
// Only stop the search if the group contains at least one empty element.
1722-
// Otherwise, the element that we are looking for might be in a following group.
1723-
if likely(group.match_empty().any_bit_set()) {
1724-
// We must have found a insert slot by now, since the current group contains at
1725-
// least one. For tables smaller than the group width, there will still be an
1726-
// empty element in the current (and only) group due to the load factor.
1727-
unsafe {
1728-
// SAFETY:
1729-
// * Caller of this function ensures that the control bytes are properly initialized.
1730-
//
1731-
// * We use this function with the slot / index found by `self.find_insert_slot_in_group`
1732-
return Err(self.fix_insert_slot(insert_slot.unwrap_unchecked()));
1721+
if let Some(insert_slot) = insert_slot {
1722+
// Only stop the search if the group contains at least one empty element.
1723+
// Otherwise, the element that we are looking for might be in a following group.
1724+
if likely(group.match_empty().any_bit_set()) {
1725+
// We must have found a insert slot by now, since the current group contains at
1726+
// least one. For tables smaller than the group width, there will still be an
1727+
// empty element in the current (and only) group due to the load factor.
1728+
unsafe {
1729+
// SAFETY:
1730+
// * Caller of this function ensures that the control bytes are properly initialized.
1731+
//
1732+
// * We use this function with the slot / index found by `self.find_insert_slot_in_group`
1733+
return Err(self.fix_insert_slot(insert_slot));
1734+
}
17331735
}
17341736
}
17351737

0 commit comments

Comments
 (0)