[llvm] [BOLT] Avoid creating a temporary instance of std::string (NFC) (PR #140987)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 19:24:13 PDT 2025


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

lookupTarget takes StringRef and internally creates an instance of
std::string with the StringRef as part of constructing Triple, so we
don't need to create a temporary instance of std::string on our own.


>From 1754bb46c83e3e1a6ba06b3c0ad8a4f4ebd89919 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 21 May 2025 15:51:03 -0700
Subject: [PATCH] [BOLT] Avoid creating a temporary instance of std::string
 (NFC)

lookupTarget takes StringRef and internally creates an instance of
std::string with the StringRef as part of constructing Triple, so we
don't need to create a temporary instance of std::string on our own.
---
 bolt/lib/Core/BinaryContext.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 82ede09c29ddf..73059ef23775a 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -201,7 +201,7 @@ Expected<std::unique_ptr<BinaryContext>> BinaryContext::createBinaryContext(
 
   std::string Error;
   const Target *TheTarget =
-      TargetRegistry::lookupTarget(std::string(ArchName), TheTriple, Error);
+      TargetRegistry::lookupTarget(ArchName, TheTriple, Error);
   if (!TheTarget)
     return createStringError(make_error_code(std::errc::not_supported),
                              Twine("BOLT-ERROR: ", Error));



More information about the llvm-commits mailing list