Skip to content

Commit 91c36ed

Browse files
committed
Make find_potential and insert_potential public. Make insert_potential unsafe
1 parent 9e82153 commit 91c36ed

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/map.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,11 +1262,14 @@ where
12621262
let hash = make_insert_hash::<K, S>(&self.hash_builder, &k);
12631263
self.table
12641264
.reserve(1, make_hasher::<K, _, V, S>(&self.hash_builder));
1265-
match self.table.find_potential(hash, equivalent_key(&k)) {
1266-
Ok(bucket) => Some(mem::replace(&mut unsafe { bucket.as_mut() }.1, v)),
1267-
Err(index) => {
1268-
self.table.insert_potential(hash, (k, v), index);
1269-
None
1265+
1266+
unsafe {
1267+
match self.table.find_potential(hash, equivalent_key(&k)) {
1268+
Ok(bucket) => Some(mem::replace(&mut bucket.as_mut().1, v)),
1269+
Err(index) => {
1270+
self.table.insert_potential(hash, (k, v), index);
1271+
None
1272+
}
12701273
}
12711274
}
12721275
}

src/raw/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
964964
/// Searches for an element in the table,
965965
/// or a potential slot where that element could be inserted.
966966
#[inline]
967-
pub(crate) fn find_potential(
967+
pub fn find_potential(
968968
&self,
969969
hash: u64,
970970
eq: impl FnMut(&T) -> bool,
@@ -1020,14 +1020,12 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
10201020

10211021
/// Inserts an element in the table at a potential slot as returned by `find_potential`.
10221022
#[inline]
1023-
pub(crate) fn insert_potential(&mut self, hash: u64, value: T, index: usize) -> Bucket<T> {
1024-
unsafe {
1025-
let old_ctrl = *self.table.ctrl(index);
1026-
self.table.record_item_insert_at(index, old_ctrl, hash);
1027-
let bucket = self.table.bucket(index);
1028-
bucket.write(value);
1029-
bucket
1030-
}
1023+
pub unsafe fn insert_potential(&mut self, hash: u64, value: T, index: usize) -> Bucket<T> {
1024+
let old_ctrl = *self.table.ctrl(index);
1025+
self.table.record_item_insert_at(index, old_ctrl, hash);
1026+
let bucket = self.table.bucket(index);
1027+
bucket.write(value);
1028+
bucket
10311029
}
10321030

10331031
/// Searches for an element in the table.

0 commit comments

Comments
 (0)