[NFC][testing] Return underlying strings directly instead of OS.str()

This avoids an unnecessary copy required by 'return OS.str()', allowing
instead for NRVO or implicit move. The .str() call (which flushes the
stream) is no longer required since 65b13610a5,
which made raw_string_ostream unbuffered by default.

Differential Revision: https://reviews.llvm.org/D115374
This commit is contained in:
Logan Smith 2021-12-09 14:55:44 -08:00
parent ad17ea12e7
commit 08eb614e30
4 changed files with 7 additions and 7 deletions

View File

@ -73,7 +73,7 @@ struct TestClangConfig {
std::string Result; std::string Result;
llvm::raw_string_ostream OS(Result); llvm::raw_string_ostream OS(Result);
OS << "{ Language=" << Language << ", Target=" << Target << " }"; OS << "{ Language=" << Language << ", Target=" << Target << " }";
return OS.str(); return Result;
} }
friend std::ostream &operator<<(std::ostream &OS, friend std::ostream &operator<<(std::ostream &OS,

View File

@ -111,7 +111,7 @@ template <typename... NodeType> std::string dumpASTString(NodeType &&... N) {
Dumper.Visit(std::forward<NodeType &&>(N)...); Dumper.Visit(std::forward<NodeType &&>(N)...);
return OS.str(); return Buffer;
} }
template <typename... NodeType> template <typename... NodeType>
@ -126,7 +126,7 @@ std::string dumpASTString(TraversalKind TK, NodeType &&... N) {
Dumper.Visit(std::forward<NodeType &&>(N)...); Dumper.Visit(std::forward<NodeType &&>(N)...);
return OS.str(); return Buffer;
} }
const FunctionDecl *getFunctionNode(clang::ASTUnit *AST, const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,

View File

@ -95,14 +95,14 @@ protected:
std::string Buf; std::string Buf;
llvm::raw_string_ostream OS{Buf}; llvm::raw_string_ostream OS{Buf};
Ctx.dumpExpandedTextsToStream(OS); Ctx.dumpExpandedTextsToStream(OS);
return OS.str(); return Buf;
} }
static std::string dumpExpansionRanges(const MacroExpansionContext &Ctx) { static std::string dumpExpansionRanges(const MacroExpansionContext &Ctx) {
std::string Buf; std::string Buf;
llvm::raw_string_ostream OS{Buf}; llvm::raw_string_ostream OS{Buf};
Ctx.dumpExpansionRangesToStream(OS); Ctx.dumpExpansionRangesToStream(OS);
return OS.str(); return Buf;
} }
}; };

View File

@ -203,7 +203,7 @@ protected:
OS << "]"; OS << "]";
return OS.str(); return Storage;
} }
std::string dumpNodes(ArrayRef<Node *> Nodes) { std::string dumpNodes(ArrayRef<Node *> Nodes) {
@ -218,7 +218,7 @@ protected:
OS << "]"; OS << "]";
return OS.str(); return Storage;
} }
}; };