mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 20:14:23 +08:00
Avoid hashing the key in prefetch() for small tables.
Also: - Assert that we aren't reading control when the table has capacity 0 because it is uninitialized in that case. - Use [[maybe_unused]] instead of cast to void. - Add NOLINT for erroneous "assert can be static_assert" lint warning. PiperOrigin-RevId: 763859124 Change-Id: Id8b8acb24882357e75cfe751e9b62fb94befddfa
This commit is contained in:
committed by
Copybara-Service
parent
e4c43850ad
commit
bd4bfed9ba
@@ -669,8 +669,12 @@ void ResizeNonSooImpl(CommonFields& common,
|
||||
ABSL_SWISSTABLE_ASSERT(new_capacity > policy.soo_capacity());
|
||||
|
||||
const size_t old_capacity = common.capacity();
|
||||
[[maybe_unused]] ctrl_t* old_ctrl = common.control();
|
||||
[[maybe_unused]] void* old_slots = common.slot_array();
|
||||
[[maybe_unused]] ctrl_t* old_ctrl;
|
||||
[[maybe_unused]] void* old_slots;
|
||||
if constexpr (kMode == ResizeNonSooMode::kGuaranteedAllocated) {
|
||||
old_ctrl = common.control();
|
||||
old_slots = common.slot_array();
|
||||
}
|
||||
|
||||
const size_t slot_size = policy.slot_size;
|
||||
const size_t slot_align = policy.slot_align;
|
||||
@@ -879,7 +883,7 @@ void GrowIntoSingleGroupShuffleControlBytes(ctrl_t* __restrict old_ctrl,
|
||||
return;
|
||||
}
|
||||
|
||||
ABSL_SWISSTABLE_ASSERT(Group::kWidth == 16);
|
||||
ABSL_SWISSTABLE_ASSERT(Group::kWidth == 16); // NOLINT(misc-static-assert)
|
||||
|
||||
// Fill the second half of the main control bytes with kEmpty.
|
||||
// For small capacity that may write into mirrored control bytes.
|
||||
|
||||
@@ -282,10 +282,8 @@ void SwapAlloc(AllocType& lhs, AllocType& rhs,
|
||||
swap(lhs, rhs);
|
||||
}
|
||||
template <typename AllocType>
|
||||
void SwapAlloc(AllocType& lhs, AllocType& rhs,
|
||||
void SwapAlloc([[maybe_unused]] AllocType& lhs, [[maybe_unused]] AllocType& rhs,
|
||||
std::false_type /* propagate_on_container_swap */) {
|
||||
(void)lhs;
|
||||
(void)rhs;
|
||||
assert(lhs == rhs &&
|
||||
"It's UB to call swap with unequal non-propagating allocators.");
|
||||
}
|
||||
@@ -949,6 +947,7 @@ class CommonFields : public CommonFieldsGenerationInfo {
|
||||
void* soo_data() { return heap_or_soo_.get_soo_data(); }
|
||||
|
||||
ctrl_t* control() const {
|
||||
ABSL_SWISSTABLE_ASSERT(capacity() > 0);
|
||||
ABSL_SWISSTABLE_IGNORE_UNINITIALIZED_RETURN(heap_or_soo_.control().get());
|
||||
}
|
||||
|
||||
@@ -2806,12 +2805,12 @@ class raw_hash_set {
|
||||
// NOTE: This is a very low level operation and should not be used without
|
||||
// specific benchmarks indicating its importance.
|
||||
template <class K = key_type>
|
||||
void prefetch(const key_arg<K>& key) const {
|
||||
void prefetch([[maybe_unused]] const key_arg<K>& key) const {
|
||||
if (capacity() == DefaultCapacity()) return;
|
||||
(void)key;
|
||||
// Avoid probing if we won't be able to prefetch the addresses received.
|
||||
#ifdef ABSL_HAVE_PREFETCH
|
||||
prefetch_heap_block();
|
||||
if (is_small()) return;
|
||||
auto seq = probe(common(), hash_of(key));
|
||||
PrefetchToLocalCache(control() + seq.offset());
|
||||
PrefetchToLocalCache(slot_array() + seq.offset());
|
||||
|
||||
Reference in New Issue
Block a user