[clang] a0898f0 - [AST][Introspection][NFC] Remove unnecessary temporary strings.
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 18 01:25:26 PDT 2021
Author: Nathan James
Date: 2021-04-18T09:25:19+01:00
New Revision: a0898f0cecc78be913e885cfba727bd4d9c49aaf
URL: https://github.com/llvm/llvm-project/commit/a0898f0cecc78be913e885cfba727bd4d9c49aaf
DIFF: https://github.com/llvm/llvm-project/commit/a0898f0cecc78be913e885cfba727bd4d9c49aaf.diff
LOG: [AST][Introspection][NFC] Remove unnecessary temporary strings.
Added:
Modified:
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
index 497cd3bdce2ca..8ad187eedfb02 100644
--- a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
+++ b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
@@ -94,7 +94,7 @@ llvm::json::Object toJSON(llvm::StringMap<ClassData> const &Obj) {
return JsonObj;
}
-void WriteJSON(std::string JsonPath, llvm::json::Object &&ClassInheritance,
+void WriteJSON(StringRef JsonPath, llvm::json::Object &&ClassInheritance,
llvm::json::Object &&ClassesInClade,
llvm::json::Object &&ClassEntries) {
llvm::json::Object JsonObj;
@@ -213,20 +213,21 @@ void ASTSrcLocProcessor::run(const MatchFinder::MatchResult &Result) {
const auto &TArgs = Templ->getTemplateArgs();
- std::string TArgsString = (DerivedFrom->getName() + "<").str();
+ SmallString<256> TArgsString;
+ llvm::raw_svector_ostream OS(TArgsString);
+ OS << DerivedFrom->getName() << '<';
+
+ clang::PrintingPolicy PPol(Result.Context->getLangOpts());
+ PPol.TerseOutput = true;
for (unsigned I = 0; I < TArgs.size(); ++I) {
- if (I > 0) {
- TArgsString += ", ";
- }
- auto Ty = TArgs.get(I).getAsType();
- clang::PrintingPolicy PPol(Result.Context->getLangOpts());
- PPol.TerseOutput = true;
- TArgsString += Ty.getAsString(PPol);
+ if (I > 0)
+ OS << ", ";
+ TArgs.get(I).getAsType().print(OS, PPol);
}
- TArgsString += ">";
+ OS << '>';
- ClassInheritance[ClassName] = std::move(TArgsString);
+ ClassInheritance[ClassName] = TArgsString.str().str();
} else {
ClassInheritance[ClassName] = DerivedFrom->getName().str();
}
More information about the cfe-commits
mailing list