Skip to content

Commit 0e124b9

Browse files
[ADT] Use "if constexpr" with shouldReverseIterate (#161477)
This patch uses "if constexpr" whenever we call shouldReverseIterate in "if" conditions. Note that shouldReverseIterate is a constexpr function.
1 parent 59fe840 commit 0e124b9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

llvm/include/llvm/ADT/SmallPtrSet.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,20 @@ template <typename PtrType> class SmallPtrSetImpl : public SmallPtrSetImplBase {
476476
}
477477

478478
[[nodiscard]] iterator begin() const {
479-
if (shouldReverseIterate())
479+
if constexpr (shouldReverseIterate())
480480
return makeIterator(EndPointer() - 1);
481-
return makeIterator(CurArray);
481+
else
482+
return makeIterator(CurArray);
482483
}
483484
[[nodiscard]] iterator end() const { return makeIterator(EndPointer()); }
484485

485486
private:
486487
/// Create an iterator that dereferences to same place as the given pointer.
487488
iterator makeIterator(const void *const *P) const {
488-
if (shouldReverseIterate())
489+
if constexpr (shouldReverseIterate())
489490
return iterator(P == EndPointer() ? CurArray : P + 1, CurArray, *this);
490-
return iterator(P, EndPointer(), *this);
491+
else
492+
return iterator(P, EndPointer(), *this);
491493
}
492494
};
493495

llvm/lib/Support/StringMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ unsigned StringMapImpl::LookupBucketFor(StringRef Name,
8383
// Hash table unallocated so far?
8484
if (NumBuckets == 0)
8585
init(16);
86-
if (shouldReverseIterate())
86+
if constexpr (shouldReverseIterate())
8787
FullHashValue = ~FullHashValue;
8888
unsigned BucketNo = FullHashValue & (NumBuckets - 1);
8989
unsigned *HashTable = getHashTable(TheTable, NumBuckets);
@@ -142,7 +142,7 @@ int StringMapImpl::FindKey(StringRef Key, uint32_t FullHashValue) const {
142142
#ifdef EXPENSIVE_CHECKS
143143
assert(FullHashValue == hash(Key));
144144
#endif
145-
if (shouldReverseIterate())
145+
if constexpr (shouldReverseIterate())
146146
FullHashValue = ~FullHashValue;
147147
unsigned BucketNo = FullHashValue & (NumBuckets - 1);
148148
unsigned *HashTable = getHashTable(TheTable, NumBuckets);

0 commit comments

Comments
 (0)