diff options
author | Evan Brown <ezb@google.com> | 2024-03-12 14:29:39 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-03-12 14:31:30 -0700 |
commit | 038561296676d1cae4a3cee30f8c924befbb6083 (patch) | |
tree | 724042c21eb6dfc0913a1eff86ffc7da3e0f4274 /absl/container/node_hash_set.h | |
parent | 3c1f9be71ee280539f02e57c5e461b0271f54e91 (diff) | |
download | abseil-038561296676d1cae4a3cee30f8c924befbb6083.tar.gz abseil-038561296676d1cae4a3cee30f8c924befbb6083.tar.bz2 abseil-038561296676d1cae4a3cee30f8c924befbb6083.zip |
Add extern templates for common swisstable types.
Motivation: mitigate linker input size increase from swisstable optimizations.
Note: the changes in raw_hash_set.h are fixing build errors that happened when adding the explicit instantiations. The change in unchecked_deref is because set iterators have const reference access whereas map iterators have mutable reference access and the function is never actually called for sets (it's used in raw_hash_map) so it wasn't needed before. I'm not sure why the soo_slot/soo_iterator problems didn't cause compile errors earlier.
PiperOrigin-RevId: 615174043
Change-Id: Iac5eb2332a76e9b70021156fbb2b8def47a5391d
Diffstat (limited to 'absl/container/node_hash_set.h')
-rw-r--r-- | absl/container/node_hash_set.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/absl/container/node_hash_set.h b/absl/container/node_hash_set.h index 8cc4b624..77b49f9b 100644 --- a/absl/container/node_hash_set.h +++ b/absl/container/node_hash_set.h @@ -36,9 +36,13 @@ #define ABSL_CONTAINER_NODE_HASH_SET_H_ #include <cstddef> +#include <cstdint> +#include <memory> +#include <string> #include <type_traits> #include "absl/algorithm/container.h" +#include "absl/base/config.h" #include "absl/base/macros.h" #include "absl/container/internal/container_memory.h" #include "absl/container/internal/hash_function_defaults.h" // IWYU pragma: export @@ -518,6 +522,32 @@ struct IsUnorderedContainer<absl::node_hash_set<Key, Hash, KeyEqual, Allocator>> : std::true_type {}; } // namespace container_algorithm_internal + +// Explicit template instantiations for common set types in order to decrease +// linker input size. Note that explicitly instantiating node_hash_set itself +// doesn't help because it has no non-alias members. If we need to decrease +// linker input size more, we could potentially (a) add more key types, e.g. +// string_view/Cord, (b) instantiate some template member functions, e.g. +// find/insert/emplace. +#define ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(TEMPLATE, KEY) \ + TEMPLATE class absl::container_internal::raw_hash_set< \ + absl::container_internal::NodeHashSetPolicy<KEY>, \ + absl::container_internal::hash_default_hash<KEY>, \ + absl::container_internal::hash_default_eq<KEY>, std::allocator<KEY>>; + +// We use exact-width integer types rather than `int`/`long`/`long long` because +// these are the types recommended in the Google C++ style guide and which are +// commonly used in Google code. +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, int8_t); +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, int16_t); +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, int32_t); +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, int64_t); +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, uint8_t); +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, uint16_t); +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, uint32_t); +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, uint64_t); +ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, std::string); + ABSL_NAMESPACE_END } // namespace absl |