[clang-tools-extra] [clangd] Simplify ternary expressions with std::optional::value_or (NFC) (PR #111309)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 6 13:07:32 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/111309
None
>From 8ada96e7b8f1f3778288f1c9b1bdf9b72ddcecac Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 4 Oct 2024 10:00:28 -0700
Subject: [PATCH] [clangd] Simplify ternary expressions with
std::optional::value_or (NFC)
---
clang-tools-extra/clangd/FindSymbols.cpp | 2 +-
clang-tools-extra/clangd/index/MemIndex.cpp | 2 +-
clang-tools-extra/clangd/index/dex/Dex.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp
index cf2f8b62a28419..84bcbc1f2ddd3f 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -111,7 +111,7 @@ getWorkspaceSymbols(llvm::StringRef Query, int Limit,
*Req.Limit *= 5;
}
TopN<ScoredSymbolInfo, ScoredSymbolGreater> Top(
- Req.Limit ? *Req.Limit : std::numeric_limits<size_t>::max());
+ Req.Limit.value_or(std::numeric_limits<size_t>::max()));
FuzzyMatcher Filter(Req.Query);
Index->fuzzyFind(Req, [HintPath, &Top, &Filter, AnyScope = Req.AnyScope,
diff --git a/clang-tools-extra/clangd/index/MemIndex.cpp b/clang-tools-extra/clangd/index/MemIndex.cpp
index fe0ee873018b37..2665d46b97d839 100644
--- a/clang-tools-extra/clangd/index/MemIndex.cpp
+++ b/clang-tools-extra/clangd/index/MemIndex.cpp
@@ -31,7 +31,7 @@ bool MemIndex::fuzzyFind(
trace::Span Tracer("MemIndex fuzzyFind");
TopN<std::pair<float, const Symbol *>> Top(
- Req.Limit ? *Req.Limit : std::numeric_limits<size_t>::max());
+ Req.Limit.value_or(std::numeric_limits<size_t>::max()));
FuzzyMatcher Filter(Req.Query);
bool More = false;
for (const auto &Pair : Index) {
diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp
index 19dc3080f9f897..b7d3063e19b499 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.cpp
+++ b/clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -264,7 +264,7 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req,
return LHS.second > RHS.second;
};
TopN<IDAndScore, decltype(Compare)> Top(
- Req.Limit ? *Req.Limit : std::numeric_limits<size_t>::max(), Compare);
+ Req.Limit.value_or(std::numeric_limits<size_t>::max()), Compare);
for (const auto &IDAndScore : IDAndScores) {
const DocID SymbolDocID = IDAndScore.first;
const auto *Sym = Symbols[SymbolDocID];
More information about the cfe-commits
mailing list