Author: Logan Smith Date: 2021-12-09T16:05:46-08:00 New Revision: ad17ea12e70abb05b6984f530618131181be9dad
URL: https://github.com/llvm/llvm-project/commit/ad17ea12e70abb05b6984f530618131181be9dad DIFF: https://github.com/llvm/llvm-project/commit/ad17ea12e70abb05b6984f530618131181be9dad.diff LOG: [NFC][AST] 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/AST/ASTDiagnostic.cpp clang/lib/AST/AttrImpl.cpp clang/lib/AST/Decl.cpp clang/lib/AST/DeclarationName.cpp clang/lib/AST/OpenMPClause.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp index 4865f3f706b3f..2e512195fd15e 100644 --- a/clang/lib/AST/ASTDiagnostic.cpp +++ b/clang/lib/AST/ASTDiagnostic.cpp @@ -335,7 +335,7 @@ ConvertTypeToDiagnosticString(ASTContext &Context, QualType Ty, OS << "'" << S << "' (vector of " << VTy->getNumElements() << " '" << VTy->getElementType().getAsString(Context.getPrintingPolicy()) << "' " << Values << ")"; - return OS.str(); + return DecoratedString; } } diff --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp index a3b46752c5113..c2f13cf638309 100644 --- a/clang/lib/AST/AttrImpl.cpp +++ b/clang/lib/AST/AttrImpl.cpp @@ -60,7 +60,7 @@ std::string LoopHintAttr::getValueString(const PrintingPolicy &Policy) const { else OS << "disable"; OS << ")"; - return OS.str(); + return ValueName; } // Return a string suitable for identifying this attribute in diagnostics. diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index c033563592d28..e63560f1b6fea 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1589,7 +1589,7 @@ std::string NamedDecl::getQualifiedNameAsString() const { std::string QualName; llvm::raw_string_ostream OS(QualName); printQualifiedName(OS, getASTContext().getPrintingPolicy()); - return OS.str(); + return QualName; } void NamedDecl::printQualifiedName(raw_ostream &OS) const { diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp index 56cf4b457a485..b2232ddfced32 100644 --- a/clang/lib/AST/DeclarationName.cpp +++ b/clang/lib/AST/DeclarationName.cpp @@ -236,7 +236,7 @@ std::string DeclarationName::getAsString() const { std::string Result; llvm::raw_string_ostream OS(Result); OS << *this; - return OS.str(); + return Result; } void *DeclarationName::getFETokenInfoSlow() const { @@ -460,7 +460,7 @@ std::string DeclarationNameInfo::getAsString() const { std::string Result; llvm::raw_string_ostream OS(Result); OS << *this; - return OS.str(); + return Result; } raw_ostream &clang::operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo) { diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp index f721e56f7fdd1..56e140f107105 100644 --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -2454,7 +2454,7 @@ std::string OMPTraitInfo::getMangledName() const { Property.RawString); } } - return OS.str(); + return MangledName; } OMPTraitInfo::OMPTraitInfo(StringRef MangledName) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits