Skip to content

Commit 179a942

Browse files
Markus WesterlindMarwes
authored andcommitted
perf(compile): Move h2 calls into a dedicated set_ctrl_h2 function
1 parent f919e17 commit 179a942

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/raw/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
781781
// - we know there is enough space in the table.
782782
// - all elements are unique.
783783
let index = new_table.find_insert_slot(hash);
784-
new_table.set_ctrl(index, h2(hash));
784+
new_table.set_ctrl_h2(index, hash);
785785
new_table.bucket(index).copy_from_nonoverlapping(&item);
786786
}
787787

@@ -814,7 +814,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
814814

815815
let bucket = self.bucket(index);
816816
self.table.growth_left -= special_is_empty(old_ctrl) as usize;
817-
self.table.set_ctrl(index, h2(hash));
817+
self.table.set_ctrl_h2(index, hash);
818818
bucket.write(value);
819819
self.table.items += 1;
820820
bucket
@@ -871,7 +871,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
871871
let old_ctrl = *self.table.ctrl(index);
872872
self.table.growth_left -= special_is_empty(old_ctrl) as usize;
873873

874-
self.table.set_ctrl(index, h2(hash));
874+
self.table.set_ctrl_h2(index, hash);
875875
bucket.write(value);
876876
self.table.items += 1;
877877
bucket
@@ -1214,14 +1214,14 @@ impl<A: Allocator + Clone> RawTableInner<A> {
12141214
(pos.wrapping_sub(self.probe_seq(hash).pos) & self.bucket_mask) / Group::WIDTH
12151215
};
12161216
if likely(probe_index(i) == probe_index(new_i)) {
1217-
self.set_ctrl(i, h2(hash));
1217+
self.set_ctrl_h2(i, hash);
12181218
return Slot::Skip;
12191219
}
12201220

12211221
// We are moving the current item to a new position. Write
12221222
// our H2 to the control byte of the new position.
12231223
let prev_ctrl = *self.ctrl(new_i);
1224-
self.set_ctrl(new_i, h2(hash));
1224+
self.set_ctrl_h2(new_i, hash);
12251225
if prev_ctrl == EMPTY {
12261226
self.set_ctrl(i, EMPTY);
12271227
Slot::Empty(new_i)
@@ -1244,6 +1244,13 @@ impl<A: Allocator + Clone> RawTableInner<A> {
12441244
}
12451245
}
12461246

1247+
/// Sets a control byte to the hash, and possibly also the replicated control byte at
1248+
/// the end of the array.
1249+
#[inline]
1250+
unsafe fn set_ctrl_h2(&self, index: usize, hash: u64) {
1251+
self.set_ctrl(index, h2(hash))
1252+
}
1253+
12471254
/// Sets a control byte, and possibly also the replicated control byte at
12481255
/// the end of the array.
12491256
#[inline]
@@ -1577,7 +1584,7 @@ impl<T: Clone, A: Allocator + Clone> RawTable<T, A> {
15771584
// - we know there is enough space in the table.
15781585
// - all elements are unique.
15791586
let index = guard_self.table.find_insert_slot(hash);
1580-
guard_self.table.set_ctrl(index, h2(hash));
1587+
guard_self.table.set_ctrl_h2(index, hash);
15811588
guard_self.bucket(index).write(item);
15821589
}
15831590
}

0 commit comments

Comments
 (0)