Skip to content

Commit 87c3367

Browse files
author
Markus Westerlind
committed
Extract part of insert
1 parent fc23548 commit 87c3367

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/raw/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,10 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
847847
index = self.table.find_insert_slot(hash);
848848
}
849849

850+
self.table.record_item_insert_at(index, old_ctrl, hash);
851+
850852
let bucket = self.bucket(index);
851-
self.table.growth_left -= special_is_empty(old_ctrl) as usize;
852-
self.table.set_ctrl_h2(index, hash);
853853
bucket.write(value);
854-
self.table.items += 1;
855854
bucket
856855
}
857856
}
@@ -866,16 +865,14 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
866865
#[cfg_attr(feature = "inline-more", inline)]
867866
pub fn try_insert_no_grow(&mut self, hash: u64, value: T) -> Result<Bucket<T>, T> {
868867
unsafe {
869-
let index = self.find_insert_slot(hash);
870-
let old_ctrl = *self.ctrl(index);
871-
if unlikely(self.growth_left == 0 && special_is_empty(old_ctrl)) {
868+
let index = self.table.find_insert_slot(hash);
869+
let old_ctrl = *self.table.ctrl(index);
870+
if unlikely(self.table.growth_left == 0 && special_is_empty(old_ctrl)) {
872871
Err(value)
873872
} else {
873+
self.table.record_item_insert_at(index, old_ctrl, hash);
874874
let bucket = self.bucket(index);
875-
self.growth_left -= special_is_empty(old_ctrl) as usize;
876-
self.set_ctrl(index, h2(hash));
877875
bucket.write(value);
878-
self.items += 1;
879876
Ok(bucket)
880877
}
881878
}
@@ -1269,6 +1266,13 @@ impl<A: Allocator + Clone> RawTableInner<A> {
12691266
}
12701267
}
12711268

1269+
#[inline]
1270+
unsafe fn record_item_insert_at(&mut self, index: usize, old_ctrl: u8, hash: u64) {
1271+
self.growth_left -= special_is_empty(old_ctrl) as usize;
1272+
self.set_ctrl_h2(index, hash);
1273+
self.items += 1;
1274+
}
1275+
12721276
/// Sets a control byte to the hash, and possibly also the replicated control byte at
12731277
/// the end of the array.
12741278
#[inline]

0 commit comments

Comments
 (0)