Skip to content

Commit 79353f9

Browse files
committed
[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
1 parent c34d898 commit 79353f9

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

clang-tools-extra/clang-tidy/GlobList.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,12 @@ bool GlobList::contains(StringRef S) const {
6565
}
6666

6767
bool CachedGlobList::contains(StringRef S) const {
68-
switch (auto &Result = Cache[S]) {
69-
case Yes:
70-
return true;
71-
case No:
72-
return false;
73-
case None:
74-
Result = GlobList::contains(S) ? Yes : No;
75-
return Result == Yes;
76-
}
77-
llvm_unreachable("invalid enum");
68+
auto Entry = Cache.try_emplace(S);
69+
bool &Value = Entry.first->getValue();
70+
// If the entry was just inserted, determine its required value.
71+
if (Entry.second)
72+
Value = GlobList::contains(S);
73+
return Value;
7874
}
7975

8076
} // namespace tidy

clang-tools-extra/clang-tidy/GlobList.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class CachedGlobList final : public GlobList {
5959
bool contains(StringRef S) const override;
6060

6161
private:
62-
enum Tristate { None, Yes, No };
63-
mutable llvm::StringMap<Tristate> Cache;
62+
mutable llvm::StringMap<bool> Cache;
6463
};
6564

6665
} // namespace tidy

0 commit comments

Comments
 (0)