Commit 62ad2bac by Evan Brown Committed by Copybara-Service

Refactoring followup for reentrancy validation in swisstable.

The motivation for renaming AssertValidCapacity() is to avoid confusion with IsValidCapacity().

PiperOrigin-RevId: 662178137
Change-Id: If4fd15725376a899c4f40afc3db9e300c8c1edc7
parent ac267be5
......@@ -2897,7 +2897,7 @@ class raw_hash_set {
size_t max_size() const { return (std::numeric_limits<size_t>::max)(); }
ABSL_ATTRIBUTE_REINITIALIZES void clear() {
AssertValidCapacity();
AssertNotDebugCapacity();
// Iterating over this container is O(bucket_count()). When bucket_count()
// is much greater than size(), iteration becomes prohibitively expensive.
// For clear() it is more important to reuse the allocated array when the
......@@ -3151,7 +3151,7 @@ class raw_hash_set {
// This overload is necessary because otherwise erase<K>(const K&) would be
// a better match if non-const iterator is passed as an argument.
void erase(iterator it) {
AssertValidCapacity();
AssertNotDebugCapacity();
AssertIsFull(it.control(), it.generation(), it.generation_ptr(), "erase()");
destroy(it.slot());
if (is_soo()) {
......@@ -3163,7 +3163,7 @@ class raw_hash_set {
iterator erase(const_iterator first,
const_iterator last) ABSL_ATTRIBUTE_LIFETIME_BOUND {
AssertValidCapacity();
AssertNotDebugCapacity();
// We check for empty first because ClearBackingArray requires that
// capacity() > 0 as a precondition.
if (empty()) return end();
......@@ -3219,7 +3219,7 @@ class raw_hash_set {
}
node_type extract(const_iterator position) {
AssertValidCapacity();
AssertNotDebugCapacity();
AssertIsFull(position.control(), position.inner_.generation(),
position.inner_.generation_ptr(), "extract()");
auto node = CommonAccess::Transfer<node_type>(alloc_ref(), position.slot());
......@@ -3726,17 +3726,12 @@ class raw_hash_set {
lhs = std::move(rhs);
} else {
lhs.move_non_heap_or_soo_fields(rhs);
#ifndef NDEBUG
const size_t rhs_capacity = rhs.capacity();
rhs.set_capacity(kInvalidReentrance);
#endif
rhs.RunWithReentrancyGuard([&] {
lhs.RunWithReentrancyGuard([&] {
PolicyTraits::transfer(&rhs_alloc, to_slot(lhs.soo_data()),
to_slot(rhs.soo_data()));
});
#ifndef NDEBUG
rhs.set_capacity(rhs_capacity);
#endif
});
}
}
......@@ -3876,12 +3871,12 @@ class raw_hash_set {
return;
#endif
AssertHashEqConsistent(key);
AssertValidCapacity();
AssertNotDebugCapacity();
}
// Asserts that the capacity is not a sentinel invalid value.
// TODO(b/296061262): also add asserts for moved-from and destroyed states.
void AssertValidCapacity() const {
void AssertNotDebugCapacity() const {
assert(capacity() != kInvalidReentrance &&
"reentrant container access during element construction/destruction "
"is not allowed.");
......
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