[llvm] [SPIRV] Use StringRef instead of std::string (NFC) (PR #138408)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat May 3 08:30:26 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/138408

We can use StringRef for PassPrefix because it is used only with
StringRef::starts_with.


>From 0bdc4a9d29d2fd244183d5f60c8c410e1e48e750 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 3 May 2025 08:06:59 -0700
Subject: [PATCH] [SPIRV] Use StringRef instead of std::string (NFC)

We can use StringRef for PassPrefix because it is used only with
StringRef::starts_with.
---
 llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index 78c0d252cb834..c516be0297e66 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -184,11 +184,11 @@ namespace SPIRV {
 /// Parses the name part of the demangled builtin call.
 std::string lookupBuiltinNameHelper(StringRef DemangledCall,
                                     FPDecorationId *DecorationId) {
-  const static std::string PassPrefix = "(anonymous namespace)::";
+  StringRef PassPrefix = "(anonymous namespace)::";
   std::string BuiltinName;
   // Itanium Demangler result may have "(anonymous namespace)::" prefix
-  if (DemangledCall.starts_with(PassPrefix.c_str()))
-    BuiltinName = DemangledCall.substr(PassPrefix.length());
+  if (DemangledCall.starts_with(PassPrefix))
+    BuiltinName = DemangledCall.substr(PassPrefix.size());
   else
     BuiltinName = DemangledCall;
   // Extract the builtin function name and types of arguments from the call



More information about the llvm-commits mailing list