Skip to content

Commit 918972b

Browse files
committed
[clang] Strip unneeded calls to raw_string_ostream::str() (NFC)
Avoid extra layer of indirection. p.s. Also, remove calls to raw_string_ostream::flush(), which are no-ops.
1 parent 1d2f727 commit 918972b

15 files changed

+11
-19
lines changed

clang/tools/clang-refactor/ClangRefactor.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ class ClangRefactorTool {
560560
<< "' can't be invoked with the given arguments:\n";
561561
for (const auto &Opt : MissingOptions)
562562
OS << " missing '-" << Opt.getKey() << "' option\n";
563-
OS.flush();
564563
return llvm::make_error<llvm::StringError>(
565564
Error, llvm::inconvertibleErrorCode());
566565
}
@@ -591,7 +590,6 @@ class ClangRefactorTool {
591590
OS << "note: the following actions are supported:\n";
592591
for (const auto &Subcommand : SubCommands)
593592
OS.indent(2) << Subcommand->getName() << "\n";
594-
OS.flush();
595593
return llvm::make_error<llvm::StringError>(
596594
Error, llvm::inconvertibleErrorCode());
597595
}

clang/tools/driver/cc1gen_reproducer_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ static std::string generateReproducerMetaInfo(const ClangInvocationInfo &Info) {
105105
OS << '}';
106106
// FIXME: Compare unsaved file hashes and report mismatch in the reproducer.
107107
if (Info.Dump)
108-
llvm::outs() << "REPRODUCER METAINFO: " << OS.str() << "\n";
109-
return std::move(OS.str());
108+
llvm::outs() << "REPRODUCER METAINFO: " << Result << "\n";
109+
return Result;
110110
}
111111

112112
/// Generates a reproducer for a set of arguments from a specific invocation.

clang/unittests/AST/SourceLocationTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class WhileParenLocationVerifier : public MatchVerifier<WhileStmt> {
105105
RParenLoc.print(Msg, *Result.SourceManager);
106106
Msg << ">";
107107

108-
this->setFailure(Msg.str());
108+
this->setFailure(MsgStr);
109109
}
110110
}
111111
};

clang/unittests/AST/TemplateNameTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ std::string printTemplateName(TemplateName TN, const PrintingPolicy &Policy,
2121
std::string Result;
2222
llvm::raw_string_ostream Out(Result);
2323
TN.print(Out, Policy, Qual);
24-
return Out.str();
24+
return Result;
2525
}
2626

2727
TEST(TemplateName, PrintTemplate) {

clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mutatedBy(const SmallVectorImpl<BoundNodes> &Results, ASTUnit *AST) {
7878
std::string Buffer;
7979
llvm::raw_string_ostream Stream(Buffer);
8080
By->printPretty(Stream, nullptr, AST->getASTContext().getPrintingPolicy());
81-
Chain.emplace_back(StringRef(Stream.str()).trim().str());
81+
Chain.emplace_back(StringRef(Buffer).trim().str());
8282
E = dyn_cast<DeclRefExpr>(By);
8383
}
8484
return Chain;

clang/unittests/Frontend/OutputStreamTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamShared) {
6767

6868
bool Success = ExecuteCompilerInvocation(&Compiler);
6969
EXPECT_FALSE(Success);
70-
EXPECT_TRUE(!VerboseStream.str().empty());
70+
EXPECT_TRUE(!VerboseBuffer.empty());
7171
EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
7272
}
7373

clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ template <class RangeOrSet> static std::string toString(const RangeOrSet &Obj) {
2525
std::string ObjRepresentation;
2626
llvm::raw_string_ostream SS(ObjRepresentation);
2727
Obj.dump(SS);
28-
return SS.str();
28+
return ObjRepresentation;
2929
}
3030
LLVM_ATTRIBUTE_UNUSED static std::string toString(const llvm::APSInt &Point) {
3131
return toString(Point, 10);

clang/unittests/Tooling/ASTSelectionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ TEST(ASTSelectionFinder, CursorAtStartOfFunction) {
171171
std::string DumpValue;
172172
llvm::raw_string_ostream OS(DumpValue);
173173
Node->Children[0].dump(OS);
174-
ASSERT_EQ(OS.str(), "FunctionDecl \"f\" contains-selection\n");
174+
ASSERT_EQ(DumpValue, "FunctionDecl \"f\" contains-selection\n");
175175
});
176176
}
177177

clang/unittests/Tooling/DiagnosticsYamlTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ TEST(DiagnosticsYamlTest, serializesDiagnostics) {
151151
yaml::Output YAML(YamlContentStream);
152152
YAML << TUD;
153153

154-
EXPECT_EQ(YAMLContent, YamlContentStream.str());
154+
EXPECT_EQ(YAMLContent, YamlContent);
155155
}
156156

157157
TEST(DiagnosticsYamlTest, deserializesDiagnostics) {

clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class NamedDeclVisitor
6767
Decl->getNameForDiagnostic(OS,
6868
Decl->getASTContext().getPrintingPolicy(),
6969
true);
70-
Match(OS.str(), Decl->getLocation());
70+
Match(NameWithTemplateArgs, Decl->getLocation());
7171
return true;
7272
}
7373
};

0 commit comments

Comments
 (0)