Skip to content

Commit ca210f1

Browse files
ezbrcopybara-github
authored andcommitted
Avoid calling ShouldRehashForBugDetection on the first two inserts to the table.
PiperOrigin-RevId: 732959065 Change-Id: Icfc2a2dad2c0be816485af605ad13bf1cb6dd11b
1 parent f1b7d00 commit ca210f1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

absl/container/internal/raw_hash_set.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ GenerationType* EmptyGeneration() {
134134
bool CommonFieldsGenerationInfoEnabled::
135135
should_rehash_for_bug_detection_on_insert(const ctrl_t* ctrl,
136136
size_t capacity) const {
137+
// As an optimization, we avoid calling ShouldRehashForBugDetection during the
138+
// first two insertions. In these cases, we'll end up rehashing anyways.
139+
if (capacity == 0 || (capacity == 1 && IsFull(ctrl[0]))) return false;
137140
if (reserved_growth_ == kReservedGrowthJustRanOut) return true;
138141
if (reserved_growth_ > 0) return false;
139142
return ShouldRehashForBugDetection(ctrl, capacity);

0 commit comments

Comments
 (0)