From 3acde1bcb612d3ba792b46f468a5ab1eefabba83 Mon Sep 17 00:00:00 2001 From: fruffy Date: Sat, 27 Apr 2024 12:52:46 -0400 Subject: [PATCH] Use flat abseil map with util hasher. Add big_int hasher. --- ir/expression.cpp | 5 +++-- lib/hash.h | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ir/expression.cpp b/ir/expression.cpp index 50206978b96..63717ff746e 100644 --- a/ir/expression.cpp +++ b/ir/expression.cpp @@ -16,6 +16,7 @@ limitations under the License. #include +#include "absl/container/flat_hash_map.h" #include "ir/id.h" #include "ir/indexed_vector.h" #include "ir/ir.h" @@ -147,7 +148,7 @@ const IR::Constant *IR::Constant::get(const IR::Type *t, big_int v, Util::Source } // Constants are interned. Keys in the intern map are pairs of types and values. using key_t = std::tuple; - static std::map CONSTANTS; + static absl::flat_hash_map CONSTANTS; auto *&result = CONSTANTS[{tb->width_bits(), t->typeId(), tb->isSigned, v}]; if (result == nullptr) { @@ -176,7 +177,7 @@ const IR::StringLiteral *IR::StringLiteral::get(cstring value, const IR::Type *t } // String literals are interned. using key_t = std::pair; - static std::map STRINGS; + static absl::flat_hash_map STRINGS; auto *&result = STRINGS[{value, t}]; if (result == nullptr) { diff --git a/lib/hash.h b/lib/hash.h index 46097833dc3..4e31c7cc6c3 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -11,6 +11,8 @@ #include #include +#include "lib/big_int_util.h" + namespace Util { namespace Detail { @@ -176,6 +178,9 @@ struct Hasher : Detail::IntegerHasher {}; template <> struct Hasher : Detail::IntegerHasher {}; +template <> +struct Hasher : Detail::StdHasher {}; + template <> struct Hasher : Detail::FloatHasher {};