Skip to content

Commit

Permalink
[clang-tidy][NFC] Remove Tristate from CachedGlobList
Browse files Browse the repository at this point in the history
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
  • Loading branch information
njames93 committed Feb 23, 2022
1 parent c34d898 commit 79353f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
16 changes: 6 additions & 10 deletions clang-tools-extra/clang-tidy/GlobList.cpp
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clang-tidy/GlobList.h
Expand Up @@ -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
Expand Down

0 comments on commit 79353f9

Please sign in to comment.