-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ADT] Add derived() to DenseMapBase (NFC) #160977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADT] Add derived() to DenseMapBase (NFC) #160977
Conversation
This patch adds derived() to obtain the CRTP derived class, following conventions in other classes. This makes forwarder functions a little more readable.
@llvm/pr-subscribers-llvm-adt Author: Kazu Hirata (kazutakahirata) ChangesThis patch adds derived() to obtain the CRTP derived class, following Full diff: https://github.com/llvm/llvm-project/pull/160977.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 5f716751751c4..78d5b04f487fb 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -448,6 +448,11 @@ class DenseMapBase : public DebugEpochBase {
static const KeyT getTombstoneKey() { return KeyInfoT::getTombstoneKey(); }
private:
+ DerivedT &derived() { return *static_cast<DerivedT *>(this); }
+ const DerivedT &derived() const {
+ return *static_cast<const DerivedT *>(this);
+ }
+
template <typename KeyArgT, typename... Ts>
std::pair<BucketT *, bool> lookupOrInsertIntoBucket(KeyArgT &&Key,
Ts &&...Args) {
@@ -477,39 +482,27 @@ class DenseMapBase : public DebugEpochBase {
return const_iterator::makeIterator(TheBucket, buckets(), *this);
}
- unsigned getNumEntries() const {
- return static_cast<const DerivedT *>(this)->getNumEntries();
- }
+ unsigned getNumEntries() const { return derived().getNumEntries(); }
- void setNumEntries(unsigned Num) {
- static_cast<DerivedT *>(this)->setNumEntries(Num);
- }
+ void setNumEntries(unsigned Num) { derived().setNumEntries(Num); }
void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
- unsigned getNumTombstones() const {
- return static_cast<const DerivedT *>(this)->getNumTombstones();
- }
+ unsigned getNumTombstones() const { return derived().getNumTombstones(); }
- void setNumTombstones(unsigned Num) {
- static_cast<DerivedT *>(this)->setNumTombstones(Num);
- }
+ void setNumTombstones(unsigned Num) { derived().setNumTombstones(Num); }
void incrementNumTombstones() { setNumTombstones(getNumTombstones() + 1); }
void decrementNumTombstones() { setNumTombstones(getNumTombstones() - 1); }
- const BucketT *getBuckets() const {
- return static_cast<const DerivedT *>(this)->getBuckets();
- }
+ const BucketT *getBuckets() const { return derived().getBuckets(); }
- BucketT *getBuckets() { return static_cast<DerivedT *>(this)->getBuckets(); }
+ BucketT *getBuckets() { return derived().getBuckets(); }
- unsigned getNumBuckets() const {
- return static_cast<const DerivedT *>(this)->getNumBuckets();
- }
+ unsigned getNumBuckets() const { return derived().getNumBuckets(); }
BucketT *getBucketsEnd() { return getBuckets() + getNumBuckets(); }
@@ -525,9 +518,9 @@ class DenseMapBase : public DebugEpochBase {
return llvm::make_range(getBuckets(), getBucketsEnd());
}
- void grow(unsigned AtLeast) { static_cast<DerivedT *>(this)->grow(AtLeast); }
+ void grow(unsigned AtLeast) { derived().grow(AtLeast); }
- void shrink_and_clear() { static_cast<DerivedT *>(this)->shrink_and_clear(); }
+ void shrink_and_clear() { derived().shrink_and_clear(); }
template <typename LookupKeyT>
BucketT *findBucketForInsertion(const LookupKeyT &Lookup,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as long as this doesn't affect performance because of inlining heuristics
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/40627 Here is the relevant piece of the build log for the reference
|
This patch adds derived() to obtain the CRTP derived class, following conventions in other classes. This makes forwarder functions a little more readable.
This patch adds derived() to obtain the CRTP derived class, following
conventions in other classes. This makes forwarder functions a little
more readable.