Skip to content

Commit c59bc90

Browse files
committed
Minor cleanups and fixed warning
1 parent fb8508a commit c59bc90

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/raw/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,18 +829,21 @@ impl<T> RawTable<T> {
829829
pub fn insert(&mut self, hash: u64, value: T, hasher: impl Fn(&T) -> u64) -> Bucket<T> {
830830
unsafe {
831831
let mut index = self.find_insert_slot(hash);
832+
833+
// We can avoid growing the table once we have reached our load
834+
// factor if we are replacing a tombstone. This works since the
835+
// number of EMPTY slots does not change in this case.
832836
let old_ctrl = *self.ctrl(index);
833-
if self.growth_left == 0 && special_is_empty(old_ctrl) {
837+
if unlikely(self.growth_left == 0 && special_is_empty(old_ctrl)) {
834838
self.reserve(1, hasher);
835839
index = self.find_insert_slot(hash);
836-
self.growth_left -= 1;
837-
} else {
838-
self.growth_left -= special_is_empty(old_ctrl) as usize
839840
}
840-
self.items += 1;
841-
self.set_ctrl(index, h2(hash));
841+
842842
let bucket = self.bucket(index);
843+
self.growth_left -= special_is_empty(old_ctrl) as usize;
844+
self.set_ctrl(index, h2(hash));
843845
bucket.write(value);
846+
self.items += 1;
844847
bucket
845848
}
846849
}
@@ -851,6 +854,7 @@ impl<T> RawTable<T> {
851854
///
852855
/// This does not check if the given element already exists in the table.
853856
#[inline]
857+
#[cfg(feature = "rustc-internal-api")]
854858
pub fn insert_no_grow(&mut self, hash: u64, value: T) -> Bucket<T> {
855859
unsafe {
856860
let index = self.find_insert_slot(hash);

0 commit comments

Comments
 (0)