[PATCH] D52617: [clangd] Make stable_partition on include candidates less slow. NFC

Eric Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 27 12:00:36 PDT 2018


ioeric updated this revision to Diff 167361.
ioeric marked 3 inline comments as done.
ioeric added a comment.

- simplify the code.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52617

Files:
  clangd/CodeComplete.cpp


Index: clangd/CodeComplete.cpp
===================================================================
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -406,25 +406,27 @@
           Includes.shouldInsertInclude(*ResolvedDeclaring, *ResolvedInserted));
     };
     bool ShouldInsert = C.headerToInsertIfAllowed().hasValue();
-    // Calculate include paths and edits for all possible headers.
+    // Put includes with insertions after those without.
+    llvm::SmallVector<CodeCompletion::IncludeCandidate, 1> InsertableCandidates;
+    Completion.Includes.reserve(C.RankedIncludeHeaders.size());
+    InsertableCandidates.reserve(C.RankedIncludeHeaders.size());
     for (const auto &Inc : C.RankedIncludeHeaders) {
       if (auto ToInclude = Inserted(Inc)) {
         CodeCompletion::IncludeCandidate Include;
         Include.Header = ToInclude->first;
         if (ToInclude->second && ShouldInsert)
           Include.Insertion = Includes.insert(ToInclude->first);
-        Completion.Includes.push_back(std::move(Include));
+        (Include.Insertion ? InsertableCandidates : Completion.Includes)
+            .push_back(std::move(Include));
+
       } else
         log("Failed to generate include insertion edits for adding header "
             "(FileURI='{0}', IncludeHeader='{1}') into {2}",
             C.IndexResult->CanonicalDeclaration.FileURI, Inc, FileName);
     }
-    // Prefer includes that do not need edits (i.e. already exist).
-    std::stable_partition(Completion.Includes.begin(),
-                          Completion.Includes.end(),
-                          [](const CodeCompletion::IncludeCandidate &I) {
-                            return !I.Insertion.hasValue();
-                          });
+    if (!InsertableCandidates.empty())
+      std::move(InsertableCandidates.begin(), InsertableCandidates.end(),
+                std::back_inserter(Completion.Includes));
   }
 
   void add(const CompletionCandidate &C, CodeCompletionString *SemaCCS) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52617.167361.patch
Type: text/x-patch
Size: 1995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180927/7e981185/attachment.bin>


More information about the cfe-commits mailing list