Author: Logan Smith
Date: 2021-12-09T16:05:46-08:00
New Revision: 08eb614e309048b695a9eb0d94e636b2324de094

URL: 
https://github.com/llvm/llvm-project/commit/08eb614e309048b695a9eb0d94e636b2324de094
DIFF: 
https://github.com/llvm/llvm-project/commit/08eb614e309048b695a9eb0d94e636b2324de094.diff

LOG: [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 65b13610a5226b84889b923bae884ba395ad084d,
which made raw_string_ostream unbuffered by default.

Differential Revision: https://reviews.llvm.org/D115374

Added: 
    

Modified: 
    clang/include/clang/Testing/TestClangConfig.h
    clang/unittests/AST/ASTTraverserTest.cpp
    clang/unittests/Analysis/MacroExpansionContextTest.cpp
    clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Testing/TestClangConfig.h 
b/clang/include/clang/Testing/TestClangConfig.h
index 5d6be4f65d0ad..92d5cc3cff994 100644
--- a/clang/include/clang/Testing/TestClangConfig.h
+++ b/clang/include/clang/Testing/TestClangConfig.h
@@ -73,7 +73,7 @@ struct TestClangConfig {
     std::string Result;
     llvm::raw_string_ostream OS(Result);
     OS << "{ Language=" << Language << ", Target=" << Target << " }";
-    return OS.str();
+    return Result;
   }
 
   friend std::ostream &operator<<(std::ostream &OS,

diff  --git a/clang/unittests/AST/ASTTraverserTest.cpp 
b/clang/unittests/AST/ASTTraverserTest.cpp
index d633f90b57d2d..b8eff747e3b50 100644
--- a/clang/unittests/AST/ASTTraverserTest.cpp
+++ b/clang/unittests/AST/ASTTraverserTest.cpp
@@ -111,7 +111,7 @@ template <typename... NodeType> std::string 
dumpASTString(NodeType &&... N) {
 
   Dumper.Visit(std::forward<NodeType &&>(N)...);
 
-  return OS.str();
+  return Buffer;
 }
 
 template <typename... NodeType>
@@ -126,7 +126,7 @@ std::string dumpASTString(TraversalKind TK, NodeType &&... 
N) {
 
   Dumper.Visit(std::forward<NodeType &&>(N)...);
 
-  return OS.str();
+  return Buffer;
 }
 
 const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,

diff  --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp 
b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 2e86457d276ca..7cee64c1b9b0c 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -95,14 +95,14 @@ class MacroExpansionContextTest : public ::testing::Test {
     std::string Buf;
     llvm::raw_string_ostream OS{Buf};
     Ctx.dumpExpandedTextsToStream(OS);
-    return OS.str();
+    return Buf;
   }
 
   static std::string dumpExpansionRanges(const MacroExpansionContext &Ctx) {
     std::string Buf;
     llvm::raw_string_ostream OS{Buf};
     Ctx.dumpExpansionRangesToStream(OS);
-    return OS.str();
+    return Buf;
   }
 };
 

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 06da4e80156a4..d2acd324b9ca9 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -203,7 +203,7 @@ class ListTest : public SyntaxTreeTest {
 
     OS << "]";
 
-    return OS.str();
+    return Storage;
   }
 
   std::string dumpNodes(ArrayRef<Node *> Nodes) {
@@ -218,7 +218,7 @@ class ListTest : public SyntaxTreeTest {
 
     OS << "]";
 
-    return OS.str();
+    return Storage;
   }
 };
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to