This revision was automatically updated to reflect the committed changes.
ilya-biryukov marked an inline comment as done.
Closed by commit rG5a9547b00709: [clangd] Simplify the code in Index::refs 
(authored by ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70225/new/

https://reviews.llvm.org/D70225

Files:
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/index/dex/Dex.cpp

Index: clang-tools-extra/clangd/index/dex/Dex.cpp
===================================================================
--- clang-tools-extra/clangd/index/dex/Dex.cpp
+++ clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -254,21 +254,16 @@
   trace::Span Tracer("Dex refs");
   uint32_t Remaining =
       Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
-  bool More = false;
   for (const auto &ID : Req.IDs)
     for (const auto &Ref : Refs.lookup(ID)) {
       if (!static_cast<int>(Req.Filter & Ref.Kind))
         continue;
-      if (Remaining == 0) {
-        More = true;
-        break;
-      }
-      if (Remaining > 0) {
-        --Remaining;
-        Callback(Ref);
-      }
+      if (Remaining == 0)
+        return true; // More refs were available.
+      --Remaining;
+      Callback(Ref);
     }
-  return More;
+  return false; // We reported all refs.
 }
 
 void Dex::relations(
Index: clang-tools-extra/clangd/index/Merge.cpp
===================================================================
--- clang-tools-extra/clangd/index/Merge.cpp
+++ clang-tools-extra/clangd/index/Merge.cpp
@@ -107,23 +107,24 @@
   More |= Dynamic->refs(Req, [&](const Ref &O) {
     DynamicIndexFileURIs.insert(O.Location.FileURI);
     Callback(O);
+    assert(Remaining != 0);
     --Remaining;
   });
   if (Remaining == 0 && More)
     return More;
   // We return less than Req.Limit if static index returns more refs for dirty
   // files.
-  More |= Static->refs(Req, [&](const Ref &O) {
+  bool StaticHadMore =  Static->refs(Req, [&](const Ref &O) {
     if (DynamicIndexFileURIs.count(O.Location.FileURI))
       return; // ignore refs that have been seen from dynamic index.
-    if (Remaining == 0)
+    if (Remaining == 0) {
       More = true;
-    if (Remaining > 0) {
-      --Remaining;
-      Callback(O);
+      return;
     }
+    --Remaining;
+    Callback(O);
   });
-  return More;
+  return More || StaticHadMore;
 }
 
 void MergedIndex::relations(
Index: clang-tools-extra/clangd/index/MemIndex.cpp
===================================================================
--- clang-tools-extra/clangd/index/MemIndex.cpp
+++ clang-tools-extra/clangd/index/MemIndex.cpp
@@ -72,7 +72,6 @@
   trace::Span Tracer("MemIndex refs");
   uint32_t Remaining =
       Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
-  bool More = false;
   for (const auto &ReqID : Req.IDs) {
     auto SymRefs = Refs.find(ReqID);
     if (SymRefs == Refs.end())
@@ -80,17 +79,13 @@
     for (const auto &O : SymRefs->second) {
       if (!static_cast<int>(Req.Filter & O.Kind))
         continue;
-      if (Remaining == 0) {
-        More = true;
-        break;
-      }
-      if (Remaining > 0) {
-        --Remaining;
-        Callback(O);
-      }
+      if (Remaining == 0)
+        return true; // More refs were available.
+      --Remaining;
+      Callback(O);
     }
   }
-  return More;
+  return false; // We reported all refs.
 }
 
 void MemIndex::relations(
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to