Skip to content

Commit

Permalink
[NFC][AST] Return underlying strings directly instead of OS.str()
Browse files Browse the repository at this point in the history
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 65b1361,
which made raw_string_ostream unbuffered by default.

Differential Revision: https://reviews.llvm.org/D115374
  • Loading branch information
kepler-5 committed Dec 10, 2021
1 parent 715c72b commit ad17ea1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTDiagnostic.cpp
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/AttrImpl.cpp
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Decl.cpp
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/DeclarationName.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/OpenMPClause.cpp
Expand Up @@ -2454,7 +2454,7 @@ std::string OMPTraitInfo::getMangledName() const {
Property.RawString);
}
}
return OS.str();
return MangledName;
}

OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {
Expand Down

0 comments on commit ad17ea1

Please sign in to comment.