[PATCH] D120196: [clang-tidy][NFC] Remove Tristate from CachedGlobList

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 23 00:35:46 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG79353f940cf4: [clang-tidy][NFC] Remove Tristate from CachedGlobList (authored by njames93).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120196/new/

https://reviews.llvm.org/D120196

Files:
  clang-tools-extra/clang-tidy/GlobList.cpp
  clang-tools-extra/clang-tidy/GlobList.h


Index: clang-tools-extra/clang-tidy/GlobList.h
===================================================================
--- clang-tools-extra/clang-tidy/GlobList.h
+++ clang-tools-extra/clang-tidy/GlobList.h
@@ -59,8 +59,7 @@
   bool contains(StringRef S) const override;
 
 private:
-  enum Tristate { None, Yes, No };
-  mutable llvm::StringMap<Tristate> Cache;
+  mutable llvm::StringMap<bool> Cache;
 };
 
 } // namespace tidy
Index: clang-tools-extra/clang-tidy/GlobList.cpp
===================================================================
--- clang-tools-extra/clang-tidy/GlobList.cpp
+++ clang-tools-extra/clang-tidy/GlobList.cpp
@@ -65,16 +65,12 @@
 }
 
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120196.410733.patch
Type: text/x-patch
Size: 1191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220223/1364aa12/attachment.bin>


More information about the cfe-commits mailing list