Skip to content

Commit b7921f8

Browse files
[ADT] Modernize Bitset (NFC) (#162430)
This patch modernizes BitWord and BITWORD_SIZE with "using" and "static constexpr", respectively.
1 parent 348ffe8 commit b7921f8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

llvm/include/llvm/ADT/Bitset.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ namespace llvm {
2828
/// initialization.
2929
template <unsigned NumBits>
3030
class Bitset {
31-
typedef uintptr_t BitWord;
31+
using BitWord = uintptr_t;
3232

33-
enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT };
33+
static constexpr unsigned BitwordBits = sizeof(BitWord) * CHAR_BIT;
3434

35-
static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32,
35+
static_assert(BitwordBits == 64 || BitwordBits == 32,
3636
"Unsupported word size");
3737

3838
static constexpr unsigned NumWords =
39-
(NumBits + BITWORD_SIZE - 1) / BITWORD_SIZE;
39+
(NumBits + BitwordBits - 1) / BitwordBits;
4040

4141
protected:
4242
using StorageType = std::array<BitWord, NumWords>;
@@ -60,23 +60,23 @@ class Bitset {
6060
}
6161

6262
constexpr Bitset &set(unsigned I) {
63-
Bits[I / BITWORD_SIZE] |= BitWord(1) << (I % BITWORD_SIZE);
63+
Bits[I / BitwordBits] |= BitWord(1) << (I % BitwordBits);
6464
return *this;
6565
}
6666

6767
constexpr Bitset &reset(unsigned I) {
68-
Bits[I / BITWORD_SIZE] &= ~(BitWord(1) << (I % BITWORD_SIZE));
68+
Bits[I / BitwordBits] &= ~(BitWord(1) << (I % BitwordBits));
6969
return *this;
7070
}
7171

7272
constexpr Bitset &flip(unsigned I) {
73-
Bits[I / BITWORD_SIZE] ^= BitWord(1) << (I % BITWORD_SIZE);
73+
Bits[I / BitwordBits] ^= BitWord(1) << (I % BitwordBits);
7474
return *this;
7575
}
7676

7777
constexpr bool operator[](unsigned I) const {
78-
BitWord Mask = BitWord(1) << (I % BITWORD_SIZE);
79-
return (Bits[I / BITWORD_SIZE] & Mask) != 0;
78+
BitWord Mask = BitWord(1) << (I % BitwordBits);
79+
return (Bits[I / BitwordBits] & Mask) != 0;
8080
}
8181

8282
constexpr bool test(unsigned I) const { return (*this)[I]; }

0 commit comments

Comments
 (0)