From: Nathan James Date: Tue, 17 Nov 2020 13:02:58 +0000 (+0000) Subject: [clang][NFC] Use SmallString instead of SmallVector Buffer; + SmallString<128> Buffer; llvm::raw_svector_ostream Out(Buffer); F->describe(Out); addDiag(CallLocation, diag::note_constexpr_call_here) << Out.str(); diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp index a9136a9..7b99546 100644 --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -1418,7 +1418,7 @@ void JSONNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *FPL) { JOS.attribute("value", FPL->getValueAsString(/*Radix=*/10)); } void JSONNodeDumper::VisitFloatingLiteral(const FloatingLiteral *FL) { - llvm::SmallVector Buffer; + llvm::SmallString<16> Buffer; FL->getValue().toString(Buffer); JOS.attribute("value", Buffer); } diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 03ceca1..30a4c51 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -808,7 +808,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd, /// QualTypeVals - Pass a vector of arrays so that QualType names can be /// compared to see if more information is needed to be printed. SmallVector QualTypeVals; - SmallVector Tree; + SmallString<64> Tree; for (unsigned i = 0, e = getNumArgs(); i < e; ++i) if (getArgKind(i) == DiagnosticsEngine::ak_qualtype) diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index 80465c4..45a2a91 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -162,8 +162,7 @@ parseCrossTUIndex(StringRef IndexPath) { StringRef LookupName = LineRef.substr(0, Delimiter); // Store paths with posix-style directory separator. - SmallVector FilePath; - llvm::Twine{LineRef.substr(Delimiter + 1)}.toVector(FilePath); + SmallString<32> FilePath(LineRef.substr(Delimiter + 1)); llvm::sys::path::native(FilePath, llvm::sys::path::Style::posix); bool InsertionOccured; @@ -624,15 +623,14 @@ parseInvocationList(StringRef FileContent, llvm::sys::path::Style PathStyle) { return llvm::make_error( index_error_code::invocation_list_wrong_format); - SmallVector ValueStorage; + SmallString<32> ValueStorage; StringRef SourcePath = Key->getValue(ValueStorage); // Store paths with PathStyle directory separator. - SmallVector NativeSourcePath; - llvm::Twine{SourcePath}.toVector(NativeSourcePath); + SmallString<32> NativeSourcePath(SourcePath); llvm::sys::path::native(NativeSourcePath, PathStyle); - StringRef InvocationKey{NativeSourcePath.begin(), NativeSourcePath.size()}; + StringRef InvocationKey(NativeSourcePath); if (InvocationList.find(InvocationKey) != InvocationList.end()) return llvm::make_error( diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 7effb15..3901c5e 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -1818,7 +1818,7 @@ bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) { loc = getSourceManager().getExpansionLoc(loc); // If that's written with the name, stop here. - SmallVector buffer; + SmallString<16> buffer; if (getPreprocessor().getSpelling(loc, buffer) == name) { locref = loc; return true; diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 0b7fe0c..e8e34c3 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -584,7 +584,7 @@ void Sema::PrintInstantiationStack() { case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: { TemplateDecl *Template = cast(Active->Template); - SmallVector TemplateArgsStr; + SmallString<128> TemplateArgsStr; llvm::raw_svector_ostream OS(TemplateArgsStr); Template->printName(OS); printTemplateArgumentList(OS, Active->template_arguments(), @@ -650,7 +650,7 @@ void Sema::PrintInstantiationStack() { ParmVarDecl *Param = cast(Active->Entity); FunctionDecl *FD = cast(Param->getDeclContext()); - SmallVector TemplateArgsStr; + SmallString<128> TemplateArgsStr; llvm::raw_svector_ostream OS(TemplateArgsStr); FD->printName(OS); printTemplateArgumentList(OS, Active->template_arguments(), @@ -802,7 +802,7 @@ void Sema::PrintInstantiationStack() { assert(isa(Active->Entity)); DiagID = diag::note_checking_constraints_for_function_here; } - SmallVector TemplateArgsStr; + SmallString<128> TemplateArgsStr; llvm::raw_svector_ostream OS(TemplateArgsStr); cast(Active->Entity)->printName(OS); if (!isa(Active->Entity)) diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index c55ef98..4d1e6bf 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1622,7 +1622,7 @@ namespace { ASTWriter &Writer; // Keep track of the framework names we've used during serialization. - SmallVector FrameworkStringData; + SmallString<128> FrameworkStringData; llvm::StringMap FrameworkNameOffset; public: @@ -1709,8 +1709,7 @@ namespace { = FrameworkNameOffset.find(Data.HFI.Framework); if (Pos == FrameworkNameOffset.end()) { Offset = FrameworkStringData.size() + 1; - FrameworkStringData.append(Data.HFI.Framework.begin(), - Data.HFI.Framework.end()); + FrameworkStringData.append(Data.HFI.Framework); FrameworkStringData.push_back(0); FrameworkNameOffset[Data.HFI.Framework] = Offset; diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp index 9192b3b..52ce17d 100644 --- a/clang/lib/Serialization/GlobalModuleIndex.cpp +++ b/clang/lib/Serialization/GlobalModuleIndex.cpp @@ -905,7 +905,7 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr, } // The output buffer, into which the global index will be written. - SmallVector OutputBuffer; + SmallString<16> OutputBuffer; { llvm::BitstreamWriter OutputStream(OutputBuffer); if (Builder.writeIndex(OutputStream)) @@ -913,9 +913,8 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr, "failed writing index"); } - return llvm::writeFileAtomically( - (IndexPath + "-%%%%%%%%").str(), IndexPath, - llvm::StringRef(OutputBuffer.data(), OutputBuffer.size())); + return llvm::writeFileAtomically((IndexPath + "-%%%%%%%%").str(), IndexPath, + OutputBuffer); } namespace { diff --git a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp index 725ff10..3d44d2c 100644 --- a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -93,7 +93,7 @@ StringRef CheckerContext::getMacroNameOrSpelling(SourceLocation &Loc) { if (Loc.isMacroID()) return Lexer::getImmediateMacroName(Loc, getSourceManager(), getLangOpts()); - SmallVector buf; + SmallString<16> buf; return Lexer::getSpelling(Loc, buf, getSourceManager(), getLangOpts()); } diff --git a/clang/lib/Tooling/Refactoring/Rename/USRFinder.cpp b/clang/lib/Tooling/Refactoring/Rename/USRFinder.cpp index 23f567f..ac8ad34 100644 --- a/clang/lib/Tooling/Refactoring/Rename/USRFinder.cpp +++ b/clang/lib/Tooling/Refactoring/Rename/USRFinder.cpp @@ -133,13 +133,13 @@ const NamedDecl *getNamedDeclFor(const ASTContext &Context, } std::string getUSRForDecl(const Decl *Decl) { - llvm::SmallVector Buff; + llvm::SmallString<128> Buff; // FIXME: Add test for the nullptr case. if (Decl == nullptr || index::generateUSRForDecl(Decl, Buff)) return ""; - return std::string(Buff.data(), Buff.size()); + return std::string(Buff); } } // end namespace tooling