Skip to content

Commit

Permalink
Avoid calling ShouldRehashForBugDetection on the first two inserts …
Browse files Browse the repository at this point in the history
…to the table.

PiperOrigin-RevId: 732959065
Change-Id: Icfc2a2dad2c0be816485af605ad13bf1cb6dd11b
  • Loading branch information
ezbr authored and copybara-github committed Mar 3, 2025
1 parent f1b7d00 commit ca210f1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions absl/container/internal/raw_hash_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ GenerationType* EmptyGeneration() {
bool CommonFieldsGenerationInfoEnabled::
should_rehash_for_bug_detection_on_insert(const ctrl_t* ctrl,
size_t capacity) const {
// As an optimization, we avoid calling ShouldRehashForBugDetection during the
// first two insertions. In these cases, we'll end up rehashing anyways.
if (capacity == 0 || (capacity == 1 && IsFull(ctrl[0]))) return false;
if (reserved_growth_ == kReservedGrowthJustRanOut) return true;
if (reserved_growth_ > 0) return false;
return ShouldRehashForBugDetection(ctrl, capacity);
Expand Down

0 comments on commit ca210f1

Please sign in to comment.