aboutsummaryrefslogtreecommitdiff
path: root/absl/container/internal/raw_hash_set.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2024-01-12 12:31:42 -0800
committerCopybara-Service <copybara-worker@google.com>2024-01-12 12:32:40 -0800
commit27134f25b11e3119a2814988c3979fdc033e54e1 (patch)
tree89e5c35470166d84ac1e67025444954bb0cbbdd4 /absl/container/internal/raw_hash_set.h
parent41a2a2555588253dce0e10db4c545463c4a64731 (diff)
downloadabseil-27134f25b11e3119a2814988c3979fdc033e54e1.tar.gz
abseil-27134f25b11e3119a2814988c3979fdc033e54e1.tar.bz2
abseil-27134f25b11e3119a2814988c3979fdc033e54e1.zip
Speed up `raw_hash_map::[]` with ABSL hardening enabled by unchecking dereference of iterator returned by `try_emplace`.
PiperOrigin-RevId: 597920257 Change-Id: I1b2e8f10a2f1efa763a6f0760294beafdb6fd9c0
Diffstat (limited to 'absl/container/internal/raw_hash_set.h')
-rw-r--r--absl/container/internal/raw_hash_set.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index b6dc7548..3518bc34 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -1943,7 +1943,7 @@ class raw_hash_set {
// PRECONDITION: not an end() iterator.
reference operator*() const {
AssertIsFull(ctrl_, generation(), generation_ptr(), "operator*()");
- return PolicyTraits::element(slot_);
+ return unchecked_deref();
}
// PRECONDITION: not an end() iterator.
@@ -2023,6 +2023,10 @@ class raw_hash_set {
// Should be used when the lifetimes of the iterators are well-enough
// understood to prove that they cannot be invalid.
bool unchecked_equals(const iterator& b) { return ctrl_ == b.control(); }
+
+ // Dereferences the iterator without ABSL Hardening iterator invalidation
+ // checks.
+ reference unchecked_deref() const { return PolicyTraits::element(slot_); }
};
class const_iterator {
@@ -3159,6 +3163,8 @@ class raw_hash_set {
return {control() + i, slot_array() + i, common().generation_ptr()};
}
+ reference unchecked_deref(iterator it) { return it.unchecked_deref(); }
+
private:
friend struct RawHashSetTestOnlyAccess;