Skip to content

Commit bf241e8

Browse files
[clang] Avoid creating temporary instances of std::string (NFC) (#140988)
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 temporary instances of std::string on our own.
1 parent 09c3d14 commit bf241e8

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,7 @@ ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
502502
StringRef Prefix(ProgName);
503503
Prefix = Prefix.slice(0, LastComponent);
504504
std::string IgnoredError;
505-
bool IsRegistered =
506-
llvm::TargetRegistry::lookupTarget(std::string(Prefix), IgnoredError);
505+
bool IsRegistered = llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError);
507506
return ParsedClangName{std::string(Prefix), ModeSuffix, DS->ModeFlag,
508507
IsRegistered};
509508
}

clang/lib/Testing/CommandLineArgs.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ std::string getAnyTargetForTesting() {
103103
StringRef TargetName(Target.getName());
104104
if (TargetName == "x86-64")
105105
TargetName = "x86_64";
106-
if (llvm::TargetRegistry::lookupTarget(std::string(TargetName), Error) ==
107-
&Target) {
106+
if (llvm::TargetRegistry::lookupTarget(TargetName, Error) == &Target) {
108107
return std::string(TargetName);
109108
}
110109
}

0 commit comments

Comments
 (0)