Skip to content

Commit f0587e6

Browse files
committed
Merge search and find_potential_inner
1 parent 05bf0e9 commit f0587e6

File tree

1 file changed

+23
-41
lines changed

1 file changed

+23
-41
lines changed

src/raw/mod.rs

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,37 +1225,6 @@ impl<A: Allocator + Clone> RawTableInner<A> {
12251225
}
12261226
}
12271227

1228-
/// Searches for an element in the table, stopping at the group where `stop` returns `Some` and
1229-
/// no elements matched. Returns the bucket that matches or the result of `stop`.
1230-
#[inline]
1231-
unsafe fn search(
1232-
&self,
1233-
hash: u64,
1234-
eq: &mut dyn FnMut(usize) -> bool,
1235-
mut stop: impl FnMut(&Group, &ProbeSeq) -> Option<usize>,
1236-
) -> (usize, bool) {
1237-
let h2_hash = h2(hash);
1238-
let mut probe_seq = self.probe_seq(hash);
1239-
1240-
loop {
1241-
let group = Group::load(self.ctrl(probe_seq.pos));
1242-
1243-
for bit in group.match_byte(h2_hash).into_iter() {
1244-
let index = (probe_seq.pos + bit) & self.bucket_mask;
1245-
1246-
if likely(eq(index)) {
1247-
return (index, true);
1248-
}
1249-
}
1250-
1251-
if let Some(stop) = stop(&group, &probe_seq) {
1252-
return (stop, false);
1253-
}
1254-
1255-
probe_seq.move_next(self.bucket_mask);
1256-
}
1257-
}
1258-
12591228
/// Finds the position to insert something in a group.
12601229
#[inline]
12611230
unsafe fn find_insert_slot_in_group(
@@ -1301,29 +1270,42 @@ impl<A: Allocator + Clone> RawTableInner<A> {
13011270
) -> (usize, bool) {
13021271
unsafe {
13031272
let mut tombstone = None;
1304-
self.search(hash, eq, |group, probe_seq| {
1305-
let index = self.find_insert_slot_in_group(group, probe_seq);
1273+
1274+
let h2_hash = h2(hash);
1275+
let mut probe_seq = self.probe_seq(hash);
1276+
1277+
loop {
1278+
let group = Group::load(self.ctrl(probe_seq.pos));
1279+
1280+
for bit in group.match_byte(h2_hash).into_iter() {
1281+
let index = (probe_seq.pos + bit) & self.bucket_mask;
1282+
1283+
if likely(eq(index)) {
1284+
return (index, true);
1285+
}
1286+
}
1287+
1288+
let index = self.find_insert_slot_in_group(&group, &probe_seq);
13061289

13071290
if likely(index.is_some()) {
13081291
// Only stop the search if the group is empty. The element might be
13091292
// in a following group.
13101293
if likely(group.match_empty().any_bit_set()) {
13111294
// Use a tombstone if we found one
1312-
if unlikely(tombstone.is_some()) {
1313-
tombstone
1295+
return if unlikely(tombstone.is_some()) {
1296+
(tombstone.unwrap(), false)
13141297
} else {
1315-
index
1316-
}
1298+
(index.unwrap(), false)
1299+
};
13171300
} else {
13181301
// We found a tombstone, record it so we can return it as a potential
13191302
// insertion location.
13201303
tombstone = index;
1321-
None
13221304
}
1323-
} else {
1324-
None
13251305
}
1326-
})
1306+
1307+
probe_seq.move_next(self.bucket_mask);
1308+
}
13271309
}
13281310
}
13291311

0 commit comments

Comments
 (0)