[clang-tools-extra] b0c070e - [clangd] Simplify ternary expressions with std::optional::value_or (NFC) (#111309)

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 6 14:47:09 PDT 2024


Author: Kazu Hirata
Date: 2024-10-06T14:47:05-07:00
New Revision: b0c070e2637935030ecd36777f22542bf371ef8c

URL: https://github.com/llvm/llvm-project/commit/b0c070e2637935030ecd36777f22542bf371ef8c
DIFF: https://github.com/llvm/llvm-project/commit/b0c070e2637935030ecd36777f22542bf371ef8c.diff

LOG: [clangd] Simplify ternary expressions with std::optional::value_or (NFC) (#111309)

Added: 
    

Modified: 
    clang-tools-extra/clangd/FindSymbols.cpp
    clang-tools-extra/clangd/index/MemIndex.cpp
    clang-tools-extra/clangd/index/dex/Dex.cpp

Removed: 
    


################################################################################
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