[clang] 5336bef - [NFC][tools] Return underlying strings directly instead of OS.str()

Logan Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 9 16:06:18 PST 2021


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

URL: https://github.com/llvm/llvm-project/commit/5336befe8c3cde08cec020583700b4d2ba25ac16
DIFF: https://github.com/llvm/llvm-project/commit/5336befe8c3cde08cec020583700b4d2ba25ac16.diff

LOG: [NFC][tools] 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/lib/Tooling/Syntax/Tokens.cpp
    clang/lib/Tooling/Syntax/Tree.cpp
    clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp
index 8a31e776d0302..e2014f965c900 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -927,5 +927,5 @@ std::string TokenBuffer::dumpForTests() const {
           M.EndExpanded);
     }
   }
-  return OS.str();
+  return Dump;
 }

diff  --git a/clang/lib/Tooling/Syntax/Tree.cpp b/clang/lib/Tooling/Syntax/Tree.cpp
index 1e3a90f3a3167..c813865e95cd8 100644
--- a/clang/lib/Tooling/Syntax/Tree.cpp
+++ b/clang/lib/Tooling/Syntax/Tree.cpp
@@ -263,7 +263,7 @@ std::string syntax::Node::dumpTokens(const SourceManager &SM) const {
       OS << " ";
     }
   });
-  return OS.str();
+  return Storage;
 }
 
 void syntax::Node::assertInvariants() const {

diff  --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index beb51bcfe5948..bf694e575a9dc 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -139,7 +139,7 @@ static std::string OptLLVM(const std::string &IR, CodeGenOpt::Level OLvl) {
 
   Passes.run(*M);
 
-  return OS.str();
+  return outString;
 }
 
 // Takes a function and runs it on a set of inputs


        


More information about the cfe-commits mailing list