Author: Nathan James Date: 2022-02-23T08:35:31Z New Revision: 79353f940cf441e69f32af0a78a48baee89e8517
URL: https://github.com/llvm/llvm-project/commit/79353f940cf441e69f32af0a78a48baee89e8517 DIFF: https://github.com/llvm/llvm-project/commit/79353f940cf441e69f32af0a78a48baee89e8517.diff LOG: [clang-tidy][NFC] Remove Tristate from CachedGlobList The tristate is a little redundant as we can determine if the item was already in the cache based on the return from try_emplace. Reviewed By: salman-javed-nz Differential Revision: https://reviews.llvm.org/D120196 Added: Modified: clang-tools-extra/clang-tidy/GlobList.cpp clang-tools-extra/clang-tidy/GlobList.h Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp index fe41feef38abf..a55cac412cf63 100644 --- a/clang-tools-extra/clang-tidy/GlobList.cpp +++ b/clang-tools-extra/clang-tidy/GlobList.cpp @@ -65,16 +65,12 @@ bool GlobList::contains(StringRef S) const { } bool CachedGlobList::contains(StringRef S) const { - switch (auto &Result = Cache[S]) { - case Yes: - return true; - case No: - return false; - case None: - Result = GlobList::contains(S) ? Yes : No; - return Result == Yes; - } - llvm_unreachable("invalid enum"); + auto Entry = Cache.try_emplace(S); + bool &Value = Entry.first->getValue(); + // If the entry was just inserted, determine its required value. + if (Entry.second) + Value = GlobList::contains(S); + return Value; } } // namespace tidy diff --git a/clang-tools-extra/clang-tidy/GlobList.h b/clang-tools-extra/clang-tidy/GlobList.h index de7020ef3f165..3eec92edaa695 100644 --- a/clang-tools-extra/clang-tidy/GlobList.h +++ b/clang-tools-extra/clang-tidy/GlobList.h @@ -59,8 +59,7 @@ class CachedGlobList final : public GlobList { bool contains(StringRef S) const override; private: - enum Tristate { None, Yes, No }; - mutable llvm::StringMap<Tristate> Cache; + mutable llvm::StringMap<bool> Cache; }; } // namespace tidy _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits