diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2025-06-02 16:03:38 +0200 |
---|---|---|
committer | Matt Arsenault <arsenm2@gmail.com> | 2025-06-03 14:55:02 +0900 |
commit | d0644fa28031eaa54bff4819fb165830ea87c719 (patch) | |
tree | 568f286d4c69f94a5ee57893503d1f864326919d | |
parent | 52efdd8cb4cda57363a5bf868cae7ca82bd04513 (diff) | |
download | llvm-users/arsenm/llvm-tli-checker/avoid-temp-string-printing.zip llvm-users/arsenm/llvm-tli-checker/avoid-temp-string-printing.tar.gz llvm-users/arsenm/llvm-tli-checker/avoid-temp-string-printing.tar.bz2 |
llvm-tli-checker: Avoid a temporary string while printingusers/arsenm/llvm-tli-checker/avoid-temp-string-printing
Directly write to the output instead of building a string to
print.
-rw-r--r-- | llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp | 22 |
1 files changed, 10 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 725fe71..5d58115 100644 --- a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp +++ b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp @@ -98,16 +98,12 @@ 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 void 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; } static void reportNumberOfEntries(const TargetLibraryInfo &TLI, @@ -138,10 +134,10 @@ static void dumpTLIEntries(const TargetLibraryInfo &TLI) { StringRef Name = TLI.getName(LF); // If there is a custom name, print it. // TODO: Should we include the standard name in the printed line? - outs() << getPrintableName(Name); + printPrintableName(outs(), Name); } else { // If it's not available, refer to it by the standard name. - outs() << getPrintableName(TargetLibraryInfo::getStandardName(LF)); + printPrintableName(outs(), TargetLibraryInfo::getStandardName(LF)); } outs() << '\n'; @@ -345,7 +341,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'; } } |