From ee02e20c0817745c47ea9be8e26e9a49afc9a7fd Mon Sep 17 00:00:00 2001 From: Kirill Bobyrev Date: Thu, 10 Dec 2020 13:36:35 +0100 Subject: [PATCH] [clangd] NFC: Use SmallVector where possible SmallVector with default size is now the recommended version (D92522). Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D92788 --- clang-tools-extra/clangd/AST.cpp | 2 +- clang-tools-extra/clangd/CompileCommands.cpp | 2 +- clang-tools-extra/clangd/CompileCommands.h | 2 +- clang-tools-extra/clangd/ConfigCompile.cpp | 2 +- clang-tools-extra/clangd/FileDistance.cpp | 7 +++---- clang-tools-extra/clangd/FindTarget.cpp | 12 ++++++------ clang-tools-extra/clangd/Headers.h | 2 +- clang-tools-extra/clangd/QueryDriverDatabase.cpp | 6 +++--- clang-tools-extra/clangd/Selection.cpp | 4 ++-- clang-tools-extra/clangd/Selection.h | 2 +- clang-tools-extra/clangd/SemanticHighlighting.cpp | 2 +- clang-tools-extra/clangd/SourceCode.cpp | 4 ++-- clang-tools-extra/clangd/TUScheduler.cpp | 2 +- clang-tools-extra/clangd/TidyProvider.cpp | 4 ++-- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp | 6 +++--- clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp | 2 +- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp | 2 +- clang-tools-extra/clangd/support/Markup.cpp | 2 +- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp | 2 +- clang-tools-extra/clangd/unittests/TestIndex.cpp | 2 +- clang-tools-extra/clangd/unittests/TestTU.cpp | 2 +- clang-tools-extra/clangd/unittests/support/TraceTests.cpp | 2 +- 22 files changed, 36 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp index d1702b2..d3615e2 100644 --- a/clang-tools-extra/clangd/AST.cpp +++ b/clang-tools-extra/clangd/AST.cpp @@ -258,7 +258,7 @@ std::string printTemplateSpecializationArgs(const NamedDecl &ND) { // TemplateArgumentTypeLocs, they only have TemplateArgumentTypes. So we // create a new argument location list from TypeSourceInfo. auto STL = TSI->getTypeLoc().getAs(); - llvm::SmallVector ArgLocs; + llvm::SmallVector ArgLocs; ArgLocs.reserve(STL.getNumArgs()); for (unsigned I = 0; I < STL.getNumArgs(); ++I) ArgLocs.push_back(STL.getArgLoc(I)); diff --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp index f6210a4..96cbd88 100644 --- a/clang-tools-extra/clangd/CompileCommands.cpp +++ b/clang-tools-extra/clangd/CompileCommands.cpp @@ -367,7 +367,7 @@ llvm::ArrayRef ArgStripper::rulesFor(llvm::StringRef Arg) { for (unsigned ID = 1 /*Skip INVALID */; ID < DriverID::LastOption; ++ID) { if (PrevAlias[ID] || ID == DriverID::OPT_Xclang) continue; // Not canonical, or specially handled. - llvm::SmallVector Rules; + llvm::SmallVector Rules; // Iterate over each alias, to add rules for parsing it. for (unsigned A = ID; A != DriverID::OPT_INVALID; A = NextAlias[A]) { if (Prefixes[A] == nullptr) // option groups. diff --git a/clang-tools-extra/clangd/CompileCommands.h b/clang-tools-extra/clangd/CompileCommands.h index 3efd800..2ba17a0 100644 --- a/clang-tools-extra/clangd/CompileCommands.h +++ b/clang-tools-extra/clangd/CompileCommands.h @@ -92,7 +92,7 @@ private: static llvm::ArrayRef rulesFor(llvm::StringRef Arg); const Rule *matchingRule(llvm::StringRef Arg, unsigned Mode, unsigned &ArgCount) const; - llvm::SmallVector Rules; + llvm::SmallVector Rules; std::deque Storage; // Store strings not found in option table. }; diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp index 846c6a1..b1189e2 100644 --- a/clang-tools-extra/clangd/ConfigCompile.cpp +++ b/clang-tools-extra/clangd/ConfigCompile.cpp @@ -137,7 +137,7 @@ struct FragmentCompiler { llvm::StringRef EnumName; const Located &Input; llvm::Optional Result; - llvm::SmallVector ValidValues; + llvm::SmallVector ValidValues; public: EnumSwitch(llvm::StringRef EnumName, const Located &In, diff --git a/clang-tools-extra/clangd/FileDistance.cpp b/clang-tools-extra/clangd/FileDistance.cpp index 584c64d..e1cead3 100644 --- a/clang-tools-extra/clangd/FileDistance.cpp +++ b/clang-tools-extra/clangd/FileDistance.cpp @@ -58,8 +58,7 @@ const llvm::hash_code FileDistance::RootHash = FileDistance::FileDistance(llvm::StringMap Sources, const FileDistanceOptions &Opts) : Opts(Opts) { - llvm::DenseMap> - DownEdges; + llvm::DenseMap> DownEdges; // Compute the best distance following only up edges. // Keep track of down edges, in case we can use them to improve on this. for (const auto &S : Sources) { @@ -118,7 +117,7 @@ FileDistance::FileDistance(llvm::StringMap Sources, unsigned FileDistance::distance(llvm::StringRef Path) { auto Canonical = canonicalize(Path); unsigned Cost = Unreachable; - llvm::SmallVector Ancestors; + llvm::SmallVector Ancestors; // Walk up ancestors until we find a path we know the distance for. for (llvm::StringRef Rest = Canonical; !Rest.empty(); Rest = parent_path(Rest, llvm::sys::path::Style::posix)) { @@ -177,7 +176,7 @@ FileDistance &URIDistance::forScheme(llvm::StringRef Scheme) { } static std::pair scopeToPath(llvm::StringRef Scope) { - llvm::SmallVector Split; + llvm::SmallVector Split; Scope.split(Split, "::", /*MaxSplit=*/-1, /*KeepEmpty=*/false); return {"/" + llvm::join(Split, "/"), Split.size()}; } diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index a9aa258..fbb117c 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -750,9 +750,9 @@ explicitReferenceTargets(DynTypedNode N, DeclRelationSet Mask) { } namespace { -llvm::SmallVector refInDecl(const Decl *D) { +llvm::SmallVector refInDecl(const Decl *D) { struct Visitor : ConstDeclVisitor { - llvm::SmallVector Refs; + llvm::SmallVector Refs; void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) { // We want to keep it as non-declaration references, as the @@ -819,10 +819,10 @@ llvm::SmallVector refInDecl(const Decl *D) { return V.Refs; } -llvm::SmallVector refInStmt(const Stmt *S) { +llvm::SmallVector refInStmt(const Stmt *S) { struct Visitor : ConstStmtVisitor { // FIXME: handle more complicated cases: more ObjC, designated initializers. - llvm::SmallVector Refs; + llvm::SmallVector Refs; void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E) { Refs.push_back(ReferenceLoc{E->getNestedNameSpecifierLoc(), @@ -920,7 +920,7 @@ llvm::SmallVector refInStmt(const Stmt *S) { return V.Refs; } -llvm::SmallVector refInTypeLoc(TypeLoc L) { +llvm::SmallVector refInTypeLoc(TypeLoc L) { struct Visitor : TypeLocVisitor { llvm::Optional Ref; @@ -1114,7 +1114,7 @@ private: /// be references. However, declarations can have references inside them, /// e.g. 'namespace foo = std' references namespace 'std' and this /// function will return the corresponding reference. - llvm::SmallVector explicitReference(DynTypedNode N) { + llvm::SmallVector explicitReference(DynTypedNode N) { if (auto *D = N.get()) return refInDecl(D); if (auto *S = N.get()) diff --git a/clang-tools-extra/clangd/Headers.h b/clang-tools-extra/clangd/Headers.h index 164a200..d86a478 100644 --- a/clang-tools-extra/clangd/Headers.h +++ b/clang-tools-extra/clangd/Headers.h @@ -136,7 +136,7 @@ private: unsigned fileIndex(llvm::StringRef Name); llvm::StringMap NameToIndex; // Values are file indexes. // Maps a file's index to that of the files it includes. - llvm::DenseMap> IncludeChildren; + llvm::DenseMap> IncludeChildren; }; /// Returns a PPCallback that visits all inclusions in the main file. diff --git a/clang-tools-extra/clangd/QueryDriverDatabase.cpp b/clang-tools-extra/clangd/QueryDriverDatabase.cpp index d59263e..797771c 100644 --- a/clang-tools-extra/clangd/QueryDriverDatabase.cpp +++ b/clang-tools-extra/clangd/QueryDriverDatabase.cpp @@ -79,7 +79,7 @@ llvm::Optional parseDriverOutput(llvm::StringRef Output) { const char SIS[] = "#include <...> search starts here:"; const char SIE[] = "End of search list."; const char TS[] = "Target: "; - llvm::SmallVector Lines; + llvm::SmallVector Lines; Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false); enum { @@ -171,8 +171,8 @@ extractSystemIncludesAndTarget(PathRef Driver, llvm::StringRef Lang, llvm::Optional Redirects[] = { {""}, {""}, llvm::StringRef(StdErrPath)}; - llvm::SmallVector Args = {Driver, "-E", "-x", - Lang, "-", "-v"}; + llvm::SmallVector Args = {Driver, "-E", "-x", + Lang, "-", "-v"}; // These flags will be preserved const llvm::StringRef FlagsToPreserve[] = { diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp index 9f84b47..7e7aff5 100644 --- a/clang-tools-extra/clangd/Selection.cpp +++ b/clang-tools-extra/clangd/Selection.cpp @@ -83,8 +83,8 @@ public: // Removes the elements of Claim from the set, modifying or removing ranges // that overlap it. // Returns the continuous subranges of Claim that were actually removed. - llvm::SmallVector, 4> erase(llvm::ArrayRef Claim) { - llvm::SmallVector, 4> Out; + llvm::SmallVector> erase(llvm::ArrayRef Claim) { + llvm::SmallVector> Out; if (Claim.empty()) return Out; diff --git a/clang-tools-extra/clangd/Selection.h b/clang-tools-extra/clangd/Selection.h index df7b6ac..212cc32 100644 --- a/clang-tools-extra/clangd/Selection.h +++ b/clang-tools-extra/clangd/Selection.h @@ -123,7 +123,7 @@ public: // The parent within the selection tree. nullptr for TranslationUnitDecl. Node *Parent; // Direct children within the selection tree. - llvm::SmallVector Children; + llvm::SmallVector Children; // The corresponding node from the full AST. ast_type_traits::DynTypedNode ASTNode; // The extent to which this node is covered by the selection. diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 5397d32..1022ccd 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -605,7 +605,7 @@ toTheiaSemanticHighlightingInformation( std::vector Lines; Lines.reserve(Tokens.size()); for (const auto &Line : Tokens) { - llvm::SmallVector LineByteTokens; + llvm::SmallVector LineByteTokens; llvm::raw_svector_ostream OS(LineByteTokens); for (const auto &Token : Line.Tokens) { // Writes the token to LineByteTokens in the byte format specified by the diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index bcd5758..5424838 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -779,8 +779,8 @@ void parseNamespaceEvents(llvm::StringRef Code, const LangOptions &LangOpts, } // Returns the prefix namespaces of NS: {"" ... NS}. -llvm::SmallVector ancestorNamespaces(llvm::StringRef NS) { - llvm::SmallVector Results; +llvm::SmallVector ancestorNamespaces(llvm::StringRef NS) { + llvm::SmallVector Results; Results.push_back(NS.take_front(0)); NS.split(Results, "::", /*MaxSplit=*/-1, /*KeepEmpty=*/false); for (llvm::StringRef &R : Results) diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index baf3f91..443abcf 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -477,7 +477,7 @@ private: /// thread are not locked, as it's the only writer. ParseInputs FileInputs; /* GUARDED_BY(Mutex) */ /// Times of recent AST rebuilds, used for UpdateDebounce computation. - llvm::SmallVector + llvm::SmallVector RebuildTimes; /* GUARDED_BY(Mutex) */ /// Set to true to signal run() to finish processing. bool Done; /* GUARDED_BY(Mutex) */ diff --git a/clang-tools-extra/clangd/TidyProvider.cpp b/clang-tools-extra/clangd/TidyProvider.cpp index 687ae65..f51ac91 100644 --- a/clang-tools-extra/clangd/TidyProvider.cpp +++ b/clang-tools-extra/clangd/TidyProvider.cpp @@ -81,7 +81,7 @@ public: // Compute absolute paths to all ancestors (substrings of P.Path). // Ensure cache entries for each ancestor exist in the map. llvm::StringRef Parent = path::parent_path(AbsPath); - llvm::SmallVector Caches; + llvm::SmallVector Caches; { std::lock_guard Lock(Mu); for (auto I = path::begin(Parent, path::Style::posix), @@ -105,7 +105,7 @@ public: // This will take a (per-file) lock for each file that actually exists. std::chrono::steady_clock::time_point FreshTime = std::chrono::steady_clock::now() - MaxStaleness; - llvm::SmallVector, 4> + llvm::SmallVector> OptionStack; for (const DotClangTidyCache *Cache : Caches) if (auto Config = Cache->get(FS, FreshTime)) { diff --git a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp index 7652dbb..d7da330 100644 --- a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp +++ b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp @@ -153,7 +153,7 @@ class FuzzyFind : public Command { Request.Limit = Limit; Request.Query = Query; if (Scopes.getNumOccurrences() > 0) { - llvm::SmallVector Scopes; + llvm::SmallVector Scopes; llvm::StringRef(this->Scopes).split(Scopes, ','); Request.Scopes = {Scopes.begin(), Scopes.end()}; } @@ -339,7 +339,7 @@ std::unique_ptr openIndex(llvm::StringRef Index) { bool runCommand(std::string Request, const SymbolIndex &Index) { // Split on spaces and add required null-termination. std::replace(Request.begin(), Request.end(), ' ', '\0'); - llvm::SmallVector Args; + llvm::SmallVector Args; llvm::StringRef(Request).split(Args, '\0', /*MaxSplit=*/-1, /*KeepEmpty=*/false); if (Args.empty()) @@ -351,7 +351,7 @@ bool runCommand(std::string Request, const SymbolIndex &Index) { llvm::outs() << "Get detailed command help with e.g. `find -help`.\n"; return true; } - llvm::SmallVector FakeArgv; + llvm::SmallVector FakeArgv; for (llvm::StringRef S : Args) FakeArgv.push_back(S.data()); // Terminated by separator or end of string. diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp index 02be220..5e588cb 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp @@ -480,7 +480,7 @@ public: const tooling::Replacement DeleteFuncBody(SM, DefRange->getBegin(), SourceLen, ""); - llvm::SmallVector, 2> Edits; + llvm::SmallVector> Edits; // Edit for Target. auto FE = Effect::fileEdit(SM, SM.getFileID(*Semicolon), std::move(TargetFileReplacements)); diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp index 8feef4e..bcf9bbe 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp @@ -202,7 +202,7 @@ ExtractionContext::insertDeclaration(llvm::StringRef VarName, struct ParsedBinaryOperator { BinaryOperatorKind Kind; SourceLocation ExprLoc; - llvm::SmallVector SelectedOperands; + llvm::SmallVector SelectedOperands; // If N is a binary operator, populate this and return true. bool parse(const SelectionTree::Node &N) { diff --git a/clang-tools-extra/clangd/support/Markup.cpp b/clang-tools-extra/clangd/support/Markup.cpp index 9dffdf6..60ad946 100644 --- a/clang-tools-extra/clangd/support/Markup.cpp +++ b/clang-tools-extra/clangd/support/Markup.cpp @@ -215,7 +215,7 @@ std::string getMarkerForCodeBlock(llvm::StringRef Input) { // Trims the input and concatenates whitespace blocks into a single ` `. std::string canonicalizeSpaces(llvm::StringRef Input) { - llvm::SmallVector Words; + llvm::SmallVector Words; llvm::SplitString(Input, Words); return llvm::join(Words, " "); } diff --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp index 1acbcd9..d911179 100644 --- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp +++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp @@ -208,7 +208,7 @@ TEST(CommandMangler, ConfigEdits) { } static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) { - llvm::SmallVector Parts; + llvm::SmallVector Parts; llvm::SplitString(Argv, Parts); std::vector Args = {Parts.begin(), Parts.end()}; ArgStripper S; diff --git a/clang-tools-extra/clangd/unittests/TestIndex.cpp b/clang-tools-extra/clangd/unittests/TestIndex.cpp index 11ac423..04fcbb4 100644 --- a/clang-tools-extra/clangd/unittests/TestIndex.cpp +++ b/clang-tools-extra/clangd/unittests/TestIndex.cpp @@ -29,7 +29,7 @@ Symbol symbol(llvm::StringRef QName) { static std::string replace(llvm::StringRef Haystack, llvm::StringRef Needle, llvm::StringRef Repl) { - llvm::SmallVector Parts; + llvm::SmallVector Parts; Haystack.split(Parts, Needle); return llvm::join(Parts, Repl); } diff --git a/clang-tools-extra/clangd/unittests/TestTU.cpp b/clang-tools-extra/clangd/unittests/TestTU.cpp index f487cf7..2701940 100644 --- a/clang-tools-extra/clangd/unittests/TestTU.cpp +++ b/clang-tools-extra/clangd/unittests/TestTU.cpp @@ -187,7 +187,7 @@ const Symbol &findSymbol(const SymbolSlab &Slab, llvm::StringRef QName) { } const NamedDecl &findDecl(ParsedAST &AST, llvm::StringRef QName) { - llvm::SmallVector Components; + llvm::SmallVector Components; QName.split(Components, "::"); auto &Ctx = AST.getASTContext(); diff --git a/clang-tools-extra/clangd/unittests/support/TraceTests.cpp b/clang-tools-extra/clangd/unittests/support/TraceTests.cpp index a482212..0fda92a 100644 --- a/clang-tools-extra/clangd/unittests/support/TraceTests.cpp +++ b/clang-tools-extra/clangd/unittests/support/TraceTests.cpp @@ -154,7 +154,7 @@ protected: std::vector outputLines() { // Deliberately don't flush output stream, the tracer should do that. // This is important when clangd crashes. - llvm::SmallVector Lines; + llvm::SmallVector Lines; llvm::StringRef(Output).split(Lines, "\r\n"); return {Lines.begin(), Lines.end()}; } -- 2.7.4