Author: ioeric Date: Thu Sep 27 07:27:02 2018 New Revision: 343223 URL: http://llvm.org/viewvc/llvm-project?rev=343223&view=rev Log: [clangd] Make IncludeInserter less slow. NFC
Modified: clang-tools-extra/trunk/clangd/Headers.cpp clang-tools-extra/trunk/clangd/Headers.h Modified: clang-tools-extra/trunk/clangd/Headers.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.cpp?rev=343223&r1=343222&r2=343223&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Headers.cpp (original) +++ clang-tools-extra/trunk/clangd/Headers.cpp Thu Sep 27 07:27:02 2018 @@ -126,6 +126,12 @@ IncludeStructure::includeDepth(llvm::Str return Result; } +void IncludeInserter::addExisting(const Inclusion &Inc) { + IncludedHeaders.insert(Inc.Written); + if (!Inc.Resolved.empty()) + IncludedHeaders.insert(Inc.Resolved); +} + /// FIXME(ioeric): we might not want to insert an absolute include path if the /// path is not shortened. bool IncludeInserter::shouldInsertInclude( @@ -133,12 +139,6 @@ bool IncludeInserter::shouldInsertInclud assert(DeclaringHeader.valid() && InsertedHeader.valid()); if (FileName == DeclaringHeader.File || FileName == InsertedHeader.File) return false; - llvm::StringSet<> IncludedHeaders; - for (const auto &Inc : Inclusions) { - IncludedHeaders.insert(Inc.Written); - if (!Inc.Resolved.empty()) - IncludedHeaders.insert(Inc.Resolved); - } auto Included = [&](llvm::StringRef Header) { return IncludedHeaders.find(Header) != IncludedHeaders.end(); }; Modified: clang-tools-extra/trunk/clangd/Headers.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=343223&r1=343222&r2=343223&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Headers.h (original) +++ clang-tools-extra/trunk/clangd/Headers.h Thu Sep 27 07:27:02 2018 @@ -97,7 +97,7 @@ public: HeaderSearchInfo(HeaderSearchInfo), Inserter(FileName, Code, Style.IncludeStyle) {} - void addExisting(Inclusion Inc) { Inclusions.push_back(std::move(Inc)); } + void addExisting(const Inclusion &Inc); /// Checks whether to add an #include of the header into \p File. /// An #include will not be added if: @@ -134,8 +134,8 @@ private: StringRef Code; StringRef BuildDir; HeaderSearch &HeaderSearchInfo; - std::vector<Inclusion> Inclusions; - tooling::HeaderIncludes Inserter; // Computers insertion replacement. + llvm::StringSet<> IncludedHeaders; // Both written and resolved. + tooling::HeaderIncludes Inserter; // Computers insertion replacement. }; } // namespace clangd _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits