aboutsummaryrefslogtreecommitdiff
path: root/absl/container/internal/hash_policy_traits.h
diff options
context:
space:
mode:
authorEvan Brown <ezb@google.com>2024-03-06 10:00:52 -0800
committerCopybara-Service <copybara-worker@google.com>2024-03-06 10:01:43 -0800
commit1449c9a106b090f61441ba245c781d7d2f89000c (patch)
tree94d6ec1a8980dfa6605f9b0e50e549e3e5761f0b /absl/container/internal/hash_policy_traits.h
parent6bf3c73fdfeb62733d2a0f81b9846ff77f3a3b9f (diff)
downloadabseil-1449c9a106b090f61441ba245c781d7d2f89000c.tar.gz
abseil-1449c9a106b090f61441ba245c781d7d2f89000c.tar.bz2
abseil-1449c9a106b090f61441ba245c781d7d2f89000c.zip
Implement small object optimization in swisstable - disabled for now.
Details: - We use the space for control/slots pointers as the inline buffer. - We use a max inline capacity of 1 to make the implementation much simpler and to avoid having to randomize the iteration order for inline tables. - For iteration of inline tables, we introduce the kSooControl buffer which just has 1 full control byte followed by 1 sentinel control byte so that incrementing yields an end() iterator. We don't access kSooControl during lookups - only iteration. PiperOrigin-RevId: 613253492 Change-Id: Id98ff11842f8bef27ac7ed88138dc03b46ce4fa6
Diffstat (limited to 'absl/container/internal/hash_policy_traits.h')
-rw-r--r--absl/container/internal/hash_policy_traits.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/absl/container/internal/hash_policy_traits.h b/absl/container/internal/hash_policy_traits.h
index 86ffd1be..ec08794a 100644
--- a/absl/container/internal/hash_policy_traits.h
+++ b/absl/container/internal/hash_policy_traits.h
@@ -168,6 +168,9 @@ struct hash_policy_traits : common_policy_traits<Policy> {
#endif
}
+ // Whether small object optimization is enabled. False by default.
+ static constexpr bool soo_enabled() { return soo_enabled_impl(Rank1{}); }
+
private:
template <class Hash>
struct HashElement {
@@ -183,6 +186,18 @@ struct hash_policy_traits : common_policy_traits<Policy> {
return Policy::apply(HashElement<Hash>{*static_cast<const Hash*>(hash_fn)},
Policy::element(static_cast<slot_type*>(slot)));
}
+
+ // Use go/ranked-overloads for dispatching. Rank1 is preferred.
+ struct Rank0 {};
+ struct Rank1 : Rank0 {};
+
+ // Use auto -> decltype as an enabler.
+ template <class P = Policy>
+ static constexpr auto soo_enabled_impl(Rank1) -> decltype(P::soo_enabled()) {
+ return P::soo_enabled();
+ }
+
+ static constexpr bool soo_enabled_impl(Rank0) { return false; }
};
} // namespace container_internal