[llvm] [SPIRV] Use heterogenous lookups with std::map (NFC) (PR #115425)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 22:31:16 PST 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/115425
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
>From 7db84e951b5673d7f8b4b51129f60af0502680ab Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 7 Nov 2024 21:17:51 -0800
Subject: [PATCH] [SPIRV] Use heterogenous lookups with std::map (NFC)
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
---
llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
index e58366017966a7..d6a59addaf2d0a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
@@ -20,7 +20,7 @@
using namespace llvm;
-static const std::map<std::string, SPIRV::Extension::Extension>
+static const std::map<std::string, SPIRV::Extension::Extension, std::less<>>
SPIRVExtensionMap = {
{"SPV_EXT_shader_atomic_float_add",
SPIRV::Extension::Extension::SPV_EXT_shader_atomic_float_add},
@@ -98,7 +98,7 @@ bool SPIRVExtensionsParser::parse(cl::Option &O, llvm::StringRef ArgName,
return O.error("Invalid extension list format: " + Token.str());
llvm::StringRef ExtensionName = Token.substr(1);
- auto NameValuePair = SPIRVExtensionMap.find(ExtensionName.str());
+ auto NameValuePair = SPIRVExtensionMap.find(ExtensionName);
if (NameValuePair == SPIRVExtensionMap.end())
return O.error("Unknown SPIR-V extension: " + Token.str());
More information about the llvm-commits
mailing list