Skip to content

Commit 3576f05

Browse files
authored
llvm-tli-checker: Avoid a temporary string while printing (#156605)
Directly write to the output instead of building a string to print. Closes #142538
1 parent 2f5500e commit 3576f05

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,13 @@ static void reportArchiveChildIssue(const object::Archive::Child &C, int Index,
9898
}
9999

100100
// Return Name, and if Name is mangled, append "aka" and the demangled name.
101-
static std::string getPrintableName(StringRef Name) {
102-
std::string OutputName = "'";
103-
OutputName += Name;
104-
OutputName += "'";
101+
static raw_ostream &printPrintableName(raw_ostream &OS, StringRef Name) {
102+
OS << '\'' << Name << '\'';
103+
105104
std::string DemangledName(demangle(Name));
106-
if (Name != DemangledName) {
107-
OutputName += " aka ";
108-
OutputName += DemangledName;
109-
}
110-
return OutputName;
105+
if (Name != DemangledName)
106+
OS << " aka " << DemangledName;
107+
return OS;
111108
}
112109

113110
static void reportNumberOfEntries(const TargetLibraryInfo &TLI,
@@ -133,8 +130,8 @@ static void dumpTLIEntries(const TargetLibraryInfo &TLI) {
133130
bool IsAvailable = TLI.has(LF);
134131
StringRef FuncName = TargetLibraryInfo::getStandardName(LF);
135132

136-
outs() << (IsAvailable ? " " : "not ")
137-
<< "available: " << getPrintableName(FuncName) << '\n';
133+
outs() << (IsAvailable ? " " : "not ") << "available: ";
134+
printPrintableName(outs(), FuncName) << '\n';
138135
}
139136
}
140137

@@ -335,7 +332,9 @@ int main(int argc, char *argv[]) {
335332
constexpr char YesNo[2][4] = {"no ", "yes"};
336333
constexpr char Indicator[4][3] = {"!!", ">>", "<<", "=="};
337334
outs() << Indicator[Which] << " TLI " << YesNo[TLIHas] << " SDK "
338-
<< YesNo[SDKHas] << ": " << getPrintableName(TLIName) << '\n';
335+
<< YesNo[SDKHas] << ": ";
336+
printPrintableName(outs(), TLIName);
337+
outs() << '\n';
339338
}
340339
}
341340

0 commit comments

Comments
 (0)