Commit f7affaf3 by Evan Brown Committed by Copybara-Service

Fix a bug in iterator validation code in which we don't update the table's…

Fix a bug in iterator validation code in which we don't update the table's reserved growth if the reservation wouldn't grow the table.

PiperOrigin-RevId: 497246219
Change-Id: I9671236f56d10851c49de71c21899368be6c3a00
parent 8d77ac51
......@@ -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.
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment