[clang] [TableGen] Use heterogenous lookups with std::map (NFC) (PR #115633)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 9 22:15:26 PST 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/115633
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
>From 555068b382041e37e00891416fee3cac7982f071 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 9 Nov 2024 14:59:35 -0800
Subject: [PATCH] [TableGen] Use heterogenous lookups with std::map (NFC)
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
---
clang/utils/TableGen/NeonEmitter.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/utils/TableGen/NeonEmitter.cpp b/clang/utils/TableGen/NeonEmitter.cpp
index c6d82646b40de2..7081e5c9ae93e8 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -578,7 +578,7 @@ class Intrinsic {
class NeonEmitter {
const RecordKeeper &Records;
DenseMap<const Record *, ClassKind> ClassMap;
- std::map<std::string, std::deque<Intrinsic>> IntrinsicMap;
+ std::map<std::string, std::deque<Intrinsic>, std::less<>> IntrinsicMap;
unsigned UniqueNumber;
void createIntrinsic(const Record *R, SmallVectorImpl<Intrinsic *> &Out);
@@ -1937,9 +1937,9 @@ void Intrinsic::indexBody() {
Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types,
std::optional<std::string> MangledName) {
// First, look up the name in the intrinsic map.
- assert_with_loc(IntrinsicMap.find(Name.str()) != IntrinsicMap.end(),
+ assert_with_loc(IntrinsicMap.find(Name) != IntrinsicMap.end(),
("Intrinsic '" + Name + "' not found!").str());
- auto &V = IntrinsicMap.find(Name.str())->second;
+ auto &V = IntrinsicMap.find(Name)->second;
std::vector<Intrinsic *> GoodVec;
// Create a string to print if we end up failing.
More information about the cfe-commits
mailing list