summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/container/internal/raw_hash_set.h2
-rw-r--r--absl/container/internal/raw_hash_set_test.cc15
2 files changed, 16 insertions, 1 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index ad4c2cc5..3762820d 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -2064,8 +2064,8 @@ class raw_hash_set {
// This is after resize, to ensure that we have completed the allocation
// and have potentially sampled the hashtable.
infoz().RecordReservation(n);
- common().reset_reserved_growth(n);
}
+ common().reset_reserved_growth(n);
}
// Extension API: support for heterogeneous keys.
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc
index 3bfb15f1..8096567c 100644
--- a/absl/container/internal/raw_hash_set_test.cc
+++ b/absl/container/internal/raw_hash_set_test.cc
@@ -2292,6 +2292,21 @@ TEST(Table, InvalidIteratorUseWithReserve) {
EXPECT_DEATH_IF_SUPPORTED(*it, kInvalidIteratorDeathMessage);
}
+TEST(Table, ReservedGrowthUpdatesWhenTableDoesntGrow) {
+ IntTable t;
+ for (int i = 0; i < 8; ++i) t.insert(i);
+ // Want to insert twice without invalidating iterators so reserve.
+ const size_t cap = t.capacity();
+ t.reserve(t.size() + 2);
+ // We want to be testing the case in which the reserve doesn't grow the table.
+ ASSERT_EQ(cap, t.capacity());
+ auto it = t.find(0);
+ t.insert(100);
+ t.insert(200);
+ // `it` shouldn't have been invalidated.
+ EXPECT_EQ(*it, 0);
+}
+
} // namespace
} // namespace container_internal
ABSL_NAMESPACE_END