[clang] 5276002 - [NFC][Sema] Return underlying strings directly instead of OS.str()

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


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

URL: https://github.com/llvm/llvm-project/commit/5276002a89b9aeb4c5f920d627630b1637c68ddc
DIFF: https://github.com/llvm/llvm-project/commit/5276002a89b9aeb4c5f920d627630b1637c68ddc.diff

LOG: [NFC][Sema] 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/Sema/CodeCompleteConsumer.cpp
    clang/lib/Sema/SemaAttr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/CodeCompleteConsumer.cpp b/clang/lib/Sema/CodeCompleteConsumer.cpp
index 6c47cedfccf3f..0a2ca54e244ad 100644
--- a/clang/lib/Sema/CodeCompleteConsumer.cpp
+++ b/clang/lib/Sema/CodeCompleteConsumer.cpp
@@ -335,7 +335,7 @@ std::string CodeCompletionString::getAsString() const {
       break;
     }
   }
-  return OS.str();
+  return Result;
 }
 
 const char *CodeCompletionString::getTypedText() const {
@@ -640,7 +640,7 @@ static std::string getOverloadAsString(const CodeCompletionString &CCS) {
       break;
     }
   }
-  return OS.str();
+  return Result;
 }
 
 void PrintingCodeCompleteConsumer::ProcessOverloadCandidates(

diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 100f8e36a9b86..b694927688489 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -792,7 +792,7 @@ attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
       OS << (I.index() == Rules.size() - 1 ? ", and " : ", ");
     OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
   }
-  return OS.str();
+  return Result;
 }
 
 } // end anonymous namespace


        


More information about the cfe-commits mailing list