diff --git a/clang-tools-extra/clangd/index/MemIndex.cpp b/clang-tools-extra/clangd/index/MemIndex.cpp --- a/clang-tools-extra/clangd/index/MemIndex.cpp +++ b/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::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(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( diff --git a/clang-tools-extra/clangd/index/Merge.cpp b/clang-tools-extra/clangd/index/Merge.cpp --- a/clang-tools-extra/clangd/index/Merge.cpp +++ b/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( diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp --- a/clang-tools-extra/clangd/index/dex/Dex.cpp +++ b/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::max()); - bool More = false; for (const auto &ID : Req.IDs) for (const auto &Ref : Refs.lookup(ID)) { if (!static_cast(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(