[PATCH] D120196: [clang-tidy][NFC] Remove Tristate from CachedGlobList
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 19 15:51:56 PST 2022
njames93 created this revision.
njames93 added reviewers: alexfh, aaron.ballman, whisperity, salman-javed-nz.
Herald added subscribers: rnkovacs, xazax.hun.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
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.410111.patch
Type: text/x-patch
Size: 1191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220219/f188ff7c/attachment-0001.bin>
More information about the cfe-commits
mailing list