Commit 0f29d3e8 by Vitaly Goldshteyn Committed by Copybara-Service

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
parent 10ac811f
......@@ -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);
......
......@@ -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 =
......
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