diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp index fe41feef38abf3..a55cac412cf63d 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 de7020ef3f165d..3eec92edaa6957 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 Cache; + mutable llvm::StringMap Cache; }; } // namespace tidy