summaryrefslogtreecommitdiff
path: root/absl/container
diff options
context:
space:
mode:
authorGravatar Vitaly Goldshteyn <goldvitaly@google.com>2024-06-20 23:05:54 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-06-20 23:06:52 -0700
commit0f29d3e828949fbd7dd5e8e7e551b297ff2cdbee (patch)
tree7846c20f64e3ce9fa3adae706575959056903639 /absl/container
parent10ac811f7c3720761c0fa0cd2b3fe92116b89420 (diff)
Remove not used after all kAllowRemoveReentrance parameter from IterateOverFullSlots.
We decided to not allow reentrance in absl::erase_if and absl::container_internal::c_for_each_fast. PiperOrigin-RevId: 645273965 Change-Id: I75dfc73b93ba10f0e051bf0833723af887e1bb36
Diffstat (limited to 'absl/container')
-rw-r--r--absl/container/internal/raw_hash_set.h28
-rw-r--r--absl/container/internal/raw_hash_set_test.cc41
2 files changed, 13 insertions, 56 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index a722f522..724df193 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -1862,7 +1862,7 @@ inline void* SlotAddress(void* slot_array, size_t slot, size_t slot_size) {
// Iterates over all full slots and calls `cb(const ctrl_t*, SlotType*)`.
// If kAllowRemoveReentrance is false, no erasure from this table allowed during
// Callback call. This mode is slightly faster.
-template <bool kAllowRemoveReentrance, class SlotType, class Callback>
+template <class SlotType, class Callback>
ABSL_ATTRIBUTE_ALWAYS_INLINE inline void IterateOverFullSlots(
const CommonFields& c, SlotType* slot, Callback cb) {
const size_t cap = c.capacity();
@@ -1885,28 +1885,20 @@ ABSL_ATTRIBUTE_ALWAYS_INLINE inline void IterateOverFullSlots(
--ctrl;
--slot;
for (uint32_t i : mask) {
- if (!kAllowRemoveReentrance || ABSL_PREDICT_TRUE(IsFull(ctrl[i]))) {
- cb(ctrl + i, slot + i);
- }
+ cb(ctrl + i, slot + i);
}
return;
}
size_t remaining = c.size();
while (remaining != 0) {
for (uint32_t i : GroupFullEmptyOrDeleted(ctrl).MaskFull()) {
- if (!kAllowRemoveReentrance || ABSL_PREDICT_TRUE(IsFull(ctrl[i]))) {
- cb(ctrl + i, slot + i);
- }
+ cb(ctrl + i, slot + i);
--remaining;
}
ctrl += Group::kWidth;
- if (kAllowRemoveReentrance && *(ctrl - 1) == ctrl_t::kSentinel) {
- break;
- } else {
- assert((remaining == 0 || *(ctrl - 1) != ctrl_t::kSentinel) &&
- "element was erased from hash table unexpectedly");
- }
slot += Group::kWidth;
+ assert((remaining == 0 || *(ctrl - 1) != ctrl_t::kSentinel) &&
+ "element was erased from hash table unexpectedly");
}
}
@@ -2750,7 +2742,7 @@ class raw_hash_set {
size_t offset = cap;
const size_t shift =
is_single_group(cap) ? (PerTableSalt(control()) | 1) : 0;
- IterateOverFullSlots</*kAllowRemoveReentrance=*/false>(
+ IterateOverFullSlots(
that.common(), that.slot_array(),
[&](const ctrl_t* that_ctrl,
slot_type* that_slot) ABSL_ATTRIBUTE_ALWAYS_INLINE {
@@ -3537,7 +3529,7 @@ class raw_hash_set {
inline void destroy_slots() {
assert(!is_soo());
if (PolicyTraits::template destroy_is_trivial<Alloc>()) return;
- IterateOverFullSlots</*kAllowRemoveReentrance=*/false>(
+ IterateOverFullSlots(
common(), slot_array(),
[&](const ctrl_t*, slot_type* slot)
ABSL_ATTRIBUTE_ALWAYS_INLINE { this->destroy(slot); });
@@ -3882,7 +3874,7 @@ class raw_hash_set {
}
// We only do validation for small tables so that it's constant time.
if (capacity() > 16) return;
- IterateOverFullSlots</*kAllowRemoveReentrance=*/false>(
+ IterateOverFullSlots(
common(), slot_array(), assert_consistent);
#endif
}
@@ -4064,7 +4056,7 @@ struct HashtableFreeFunctionsAccess {
return 1;
}
size_t num_deleted = 0;
- IterateOverFullSlots</*kAllowRemoveReentrance=*/false>(
+ IterateOverFullSlots(
c->common(), c->slot_array(), [&](const ctrl_t* ctrl, auto* slot) {
if (pred(Set::PolicyTraits::element(slot))) {
c->destroy(slot);
@@ -4086,7 +4078,7 @@ struct HashtableFreeFunctionsAccess {
return;
}
using ElementTypeWithConstness = decltype(*c->begin());
- IterateOverFullSlots</*kAllowRemoveReentrance=*/false>(
+ IterateOverFullSlots(
c->common(), c->slot_array(), [&cb](const ctrl_t*, auto* slot) {
ElementTypeWithConstness& element = Set::PolicyTraits::element(slot);
cb(element);
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc
index 673d78a6..ba603d2b 100644
--- a/absl/container/internal/raw_hash_set_test.cc
+++ b/absl/container/internal/raw_hash_set_test.cc
@@ -3334,12 +3334,12 @@ TEST(Table, IterateOverFullSlotsEmpty) {
auto fail_if_any = [](const ctrl_t*, auto* i) {
FAIL() << "expected no slots " << **i;
};
- container_internal::IterateOverFullSlots</*kAllowRemoveReentrance=*/false>(
+ container_internal::IterateOverFullSlots(
RawHashSetTestOnlyAccess::GetCommon(t),
RawHashSetTestOnlyAccess::GetSlots(t), fail_if_any);
for (size_t i = 0; i < 256; ++i) {
t.reserve(i);
- container_internal::IterateOverFullSlots</*kAllowRemoveReentrance=*/false>(
+ container_internal::IterateOverFullSlots(
RawHashSetTestOnlyAccess::GetCommon(t),
RawHashSetTestOnlyAccess::GetSlots(t), fail_if_any);
}
@@ -3354,7 +3354,7 @@ TEST(Table, IterateOverFullSlotsFull) {
expected_slots.push_back(idx);
std::vector<int64_t> slots;
- container_internal::IterateOverFullSlots</*kAllowRemoveReentrance=*/false>(
+ container_internal::IterateOverFullSlots(
RawHashSetTestOnlyAccess::GetCommon(t),
RawHashSetTestOnlyAccess::GetSlots(t),
[&t, &slots](const ctrl_t* ctrl, auto* i) {
@@ -3368,41 +3368,6 @@ TEST(Table, IterateOverFullSlotsFull) {
}
}
-TEST(Table, IterateOverFullSlotsAllowReentrance) {
- std::vector<int64_t> expected_values;
- for (int64_t idx = 0; idx < 128; ++idx) {
- NonSooIntTable t;
- for (int val = 0; val <= idx; ++val) {
- t.insert(val);
- }
-
- // We are inserting only even values.
- // Only one element across 2*k and 2*k+1 should be visited.
- if (idx % 2 == 0) {
- expected_values.push_back(idx);
- }
-
- std::vector<int64_t> actual_values;
- container_internal::IterateOverFullSlots</*kAllowRemoveReentrance=*/true>(
- RawHashSetTestOnlyAccess::GetCommon(t),
- RawHashSetTestOnlyAccess::GetSlots(t),
- [&t, &actual_values](const ctrl_t* ctrl, auto* i) {
- int64_t value = **i;
- // Erase the other element from 2*k and 2*k+1 pair.
- t.erase(value ^ 1);
- ptrdiff_t ctrl_offset =
- ctrl - RawHashSetTestOnlyAccess::GetCommon(t).control();
- ptrdiff_t slot_offset = i - RawHashSetTestOnlyAccess::GetSlots(t);
- ASSERT_EQ(ctrl_offset, slot_offset);
- // Add an even value from the pair.
- // Only one element for each 2*k and 2*k+1 pair should be inserted.
- actual_values.push_back(value - value % 2);
- });
- EXPECT_THAT(actual_values,
- testing::UnorderedElementsAreArray(expected_values));
- }
-}
-
template <typename T>
class SooTable : public testing::Test {};
using FreezableSooTableTypes =