[llvm] llvm-tli-checker: Avoid a temporary string while printing (PR #156605)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 3 00:11:35 PDT 2025
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/156605
Directly write to the output instead of building a string to
print.
Closes #142538
>From 0b962a593f35020f653ae361adf56f283c029c9c Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 2 Jun 2025 16:03:38 +0200
Subject: [PATCH] llvm-tli-checker: Avoid a temporary string while printing
Directly write to the output instead of building a string to
print.
Closes #142538
---
.../llvm-tli-checker/llvm-tli-checker.cpp | 23 +++++++++----------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
index bc20386987cae..3cd5d597ee133 100644
--- a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -98,16 +98,13 @@ static void reportArchiveChildIssue(const object::Archive::Child &C, int Index,
}
// Return Name, and if Name is mangled, append "aka" and the demangled name.
-static std::string getPrintableName(StringRef Name) {
- std::string OutputName = "'";
- OutputName += Name;
- OutputName += "'";
+static raw_ostream &printPrintableName(raw_ostream &OS, StringRef Name) {
+ OS << '\'' << Name << '\'';
+
std::string DemangledName(demangle(Name));
- if (Name != DemangledName) {
- OutputName += " aka ";
- OutputName += DemangledName;
- }
- return OutputName;
+ if (Name != DemangledName)
+ OS << " aka " << DemangledName;
+ return OS;
}
static void reportNumberOfEntries(const TargetLibraryInfo &TLI,
@@ -133,8 +130,8 @@ static void dumpTLIEntries(const TargetLibraryInfo &TLI) {
bool IsAvailable = TLI.has(LF);
StringRef FuncName = TargetLibraryInfo::getStandardName(LF);
- outs() << (IsAvailable ? " " : "not ")
- << "available: " << getPrintableName(FuncName) << '\n';
+ outs() << (IsAvailable ? " " : "not ") << "available: ";
+ printPrintableName(outs(), FuncName) << '\n';
}
}
@@ -335,7 +332,9 @@ int main(int argc, char *argv[]) {
constexpr char YesNo[2][4] = {"no ", "yes"};
constexpr char Indicator[4][3] = {"!!", ">>", "<<", "=="};
outs() << Indicator[Which] << " TLI " << YesNo[TLIHas] << " SDK "
- << YesNo[SDKHas] << ": " << getPrintableName(TLIName) << '\n';
+ << YesNo[SDKHas] << ": ";
+ printPrintableName(outs(), TLIName);
+ outs() << '\n';
}
}
More information about the llvm-commits
mailing list