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

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 27 09:37:47 PDT 2018


sammccall added inline comments.


================
Comment at: clangd/CodeComplete.cpp:325
+CodeCompletion::IncludeCandidates
+moveNonInsertingIncludesToFront(CodeCompletion::IncludeCandidates Includes) {
+  if (Includes.size() <= 1)
----------------
this seems a bit overly complicated. It does seem like a worry that this code is hot enough to optimize, especially compared to *generating* the list.

But I think we can do something simpler...


================
Comment at: clangd/CodeComplete.cpp:415
     // Calculate include paths and edits for all possible headers.
+    llvm::SmallVector<CodeCompletion::IncludeCandidate, 1> IncludeCandidates;
     for (const auto &Inc : C.RankedIncludeHeaders) {
----------------
if this is really hot, you might want to reserve(C.RankedIncludeHeaders.size())


================
Comment at: clangd/CodeComplete.cpp:422
           Include.Insertion = Includes.insert(ToInclude->first);
-        Completion.Includes.push_back(std::move(Include));
+        IncludeCandidates.push_back(std::move(Include));
       } else
----------------
What about
`(Include.Insertion ? InsertableCandidates : IncludeCandidates).push_back(std::move(Include))`

where `InsertableCandidates` is a vector declared above, and then just move it onto the end of the list after the loop?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52617





More information about the cfe-commits mailing list