Skip to content

Commit 0d8a008

Browse files
committed
[lldb] Remove SetCount/ClearCount from Flags
Summary: These functions are only used in tests where we should test the actual flag values instead of counting all bits for an approximate check. Also these popcount implementation aren't very efficient and doesn't seem to be optimised to anything fast. Reviewers: davide, JDevlieghere Reviewed By: davide, JDevlieghere Subscribers: abidh, JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67540 llvm-svn: 372018
1 parent 21641a2 commit 0d8a008

File tree

2 files changed

+3
-64
lines changed

2 files changed

+3
-64
lines changed

lldb/include/lldb/Utility/Flags.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -121,32 +121,6 @@ class Flags {
121121
/// \b true if \a bit is 0, \b false otherwise.
122122
bool IsClear(ValueType bit) const { return (m_flags & bit) == 0; }
123123

124-
/// Get the number of zero bits in \a m_flags.
125-
///
126-
/// \return
127-
/// The number of bits that are set to 0 in the current flags.
128-
size_t ClearCount() const {
129-
size_t count = 0;
130-
for (ValueType shift = 0; shift < sizeof(ValueType) * 8; ++shift) {
131-
if ((m_flags & (1u << shift)) == 0)
132-
++count;
133-
}
134-
return count;
135-
}
136-
137-
/// Get the number of one bits in \a m_flags.
138-
///
139-
/// \return
140-
/// The number of bits that are set to 1 in the current flags.
141-
size_t SetCount() const {
142-
size_t count = 0;
143-
for (ValueType mask = m_flags; mask; mask >>= 1) {
144-
if (mask & 1u)
145-
++count;
146-
}
147-
return count;
148-
}
149-
150124
protected:
151125
ValueType m_flags; ///< The flags.
152126
};

lldb/unittests/Utility/FlagsTest.cpp

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,18 @@ TEST(Flags, Reset) {
3030
Flags f;
3131
f.Reset(0x3);
3232
EXPECT_EQ(0x3U, f.Get());
33-
EXPECT_EQ(2U, f.SetCount());
3433
}
3534

3635
TEST(Flags, Clear) {
3736
Flags f;
3837
f.Reset(0x3);
39-
EXPECT_EQ(2U, f.SetCount());
38+
EXPECT_EQ(0x3U, f.Get());
4039

4140
f.Clear(0x5);
42-
EXPECT_EQ(1U, f.SetCount());
41+
EXPECT_EQ(0x2U, f.Get());
4342

4443
f.Clear();
45-
EXPECT_EQ(0U, f.SetCount());
44+
EXPECT_EQ(0x0U, f.Get());
4645
}
4746

4847
TEST(Flags, AllSet) {
@@ -162,37 +161,3 @@ TEST(Flags, IsClear) {
162161
EXPECT_TRUE(f.IsClear(eFlag0));
163162
EXPECT_TRUE(f.IsClear(eFlag1));
164163
}
165-
166-
TEST(Flags, ClearCount) {
167-
Flags f;
168-
EXPECT_EQ(32U, f.ClearCount());
169-
170-
f.Set(eFlag0);
171-
EXPECT_EQ(31U, f.ClearCount());
172-
173-
f.Set(eFlag0);
174-
EXPECT_EQ(31U, f.ClearCount());
175-
176-
f.Set(eFlag1);
177-
EXPECT_EQ(30U, f.ClearCount());
178-
179-
f.Set(eAllFlags);
180-
EXPECT_EQ(29U, f.ClearCount());
181-
}
182-
183-
TEST(Flags, SetCount) {
184-
Flags f;
185-
EXPECT_EQ(0U, f.SetCount());
186-
187-
f.Set(eFlag0);
188-
EXPECT_EQ(1U, f.SetCount());
189-
190-
f.Set(eFlag0);
191-
EXPECT_EQ(1U, f.SetCount());
192-
193-
f.Set(eFlag1);
194-
EXPECT_EQ(2U, f.SetCount());
195-
196-
f.Set(eAllFlags);
197-
EXPECT_EQ(3U, f.SetCount());
198-
}

0 commit comments

Comments
 (0)