Author: omtcyfz Date: Tue Sep 11 03:31:38 2018 New Revision: 341921 URL: http://llvm.org/viewvc/llvm-project?rev=341921&view=rev Log: [clangd] NFC: Use uint32_t for FuzzyFindRequest limits
Reviewed By: ioeric Differential Revision: https://reviews.llvm.org/D51860 Modified: clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Index.h Modified: clang-tools-extra/trunk/clangd/index/Index.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=341921&r1=341920&r2=341921&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/Index.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Index.cpp Tue Sep 11 03:31:38 2018 @@ -177,29 +177,25 @@ std::shared_ptr<SymbolIndex> SwapIndex:: bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request) { json::ObjectMapper O(Parameters); - llvm::Optional<int64_t> MaxCandidateCount; + int64_t MaxCandidateCount; bool OK = O && O.map("Query", Request.Query) && O.map("Scopes", Request.Scopes) && + O.map("MaxCandidateCount", MaxCandidateCount) && O.map("RestrictForCodeCompletion", Request.RestrictForCodeCompletion) && - O.map("ProximityPaths", Request.ProximityPaths) && - O.map("MaxCandidateCount", MaxCandidateCount); - if (MaxCandidateCount) - Request.MaxCandidateCount = MaxCandidateCount.getValue(); + O.map("ProximityPaths", Request.ProximityPaths); + if (OK && MaxCandidateCount <= std::numeric_limits<uint32_t>::max()) + Request.MaxCandidateCount = MaxCandidateCount; return OK; } llvm::json::Value toJSON(const FuzzyFindRequest &Request) { - auto Result = json::Object{ + return json::Object{ {"Query", Request.Query}, {"Scopes", json::Array{Request.Scopes}}, + {"MaxCandidateCount", Request.MaxCandidateCount}, {"RestrictForCodeCompletion", Request.RestrictForCodeCompletion}, {"ProximityPaths", json::Array{Request.ProximityPaths}}, }; - // A huge limit means no limit, leave it out. - if (Request.MaxCandidateCount <= std::numeric_limits<int64_t>::max()) - Result["MaxCandidateCount"] = - static_cast<int64_t>(Request.MaxCandidateCount); - return std::move(Result); } bool SwapIndex::fuzzyFind(const FuzzyFindRequest &R, Modified: clang-tools-extra/trunk/clangd/index/Index.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=341921&r1=341920&r2=341921&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/Index.h (original) +++ clang-tools-extra/trunk/clangd/index/Index.h Tue Sep 11 03:31:38 2018 @@ -437,7 +437,9 @@ struct FuzzyFindRequest { std::vector<std::string> Scopes; /// \brief The number of top candidates to return. The index may choose to /// return more than this, e.g. if it doesn't know which candidates are best. - size_t MaxCandidateCount = std::numeric_limits<size_t>::max(); + // FIXME: Use llvm::Optional; semantically, the absence of MaxCandidateCount + // is equivalent to setting this field to default value as below. + uint32_t MaxCandidateCount = std::numeric_limits<uint32_t>::max(); /// If set to true, only symbols for completion support will be considered. bool RestrictForCodeCompletion = false; /// Contextually relevant files (e.g. the file we're code-completing in). _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits