teemperor created this revision.
teemperor added a reviewer: davide.
Herald added subscribers: lldb-commits, JDevlieghere, abidh.
Herald added a project: LLDB.
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.
Repository:
rLLDB LLDB
https://reviews.llvm.org/D67540
Files:
lldb/include/lldb/Utility/Flags.h
lldb/unittests/Utility/FlagsTest.cpp
Index: lldb/unittests/Utility/FlagsTest.cpp
===================================================================
--- lldb/unittests/Utility/FlagsTest.cpp
+++ lldb/unittests/Utility/FlagsTest.cpp
@@ -30,19 +30,18 @@
Flags f;
f.Reset(0x3);
EXPECT_EQ(0x3U, f.Get());
- EXPECT_EQ(2U, f.SetCount());
}
TEST(Flags, Clear) {
Flags f;
f.Reset(0x3);
- EXPECT_EQ(2U, f.SetCount());
+ EXPECT_EQ(0x3U, f.Get());
f.Clear(0x5);
- EXPECT_EQ(1U, f.SetCount());
+ EXPECT_EQ(0x2U, f.Get());
f.Clear();
- EXPECT_EQ(0U, f.SetCount());
+ EXPECT_EQ(0x0U, f.Get());
}
TEST(Flags, AllSet) {
@@ -162,37 +161,3 @@
EXPECT_TRUE(f.IsClear(eFlag0));
EXPECT_TRUE(f.IsClear(eFlag1));
}
-
-TEST(Flags, ClearCount) {
- Flags f;
- EXPECT_EQ(32U, f.ClearCount());
-
- f.Set(eFlag0);
- EXPECT_EQ(31U, f.ClearCount());
-
- f.Set(eFlag0);
- EXPECT_EQ(31U, f.ClearCount());
-
- f.Set(eFlag1);
- EXPECT_EQ(30U, f.ClearCount());
-
- f.Set(eAllFlags);
- EXPECT_EQ(29U, f.ClearCount());
-}
-
-TEST(Flags, SetCount) {
- Flags f;
- EXPECT_EQ(0U, f.SetCount());
-
- f.Set(eFlag0);
- EXPECT_EQ(1U, f.SetCount());
-
- f.Set(eFlag0);
- EXPECT_EQ(1U, f.SetCount());
-
- f.Set(eFlag1);
- EXPECT_EQ(2U, f.SetCount());
-
- f.Set(eAllFlags);
- EXPECT_EQ(3U, f.SetCount());
-}
Index: lldb/include/lldb/Utility/Flags.h
===================================================================
--- lldb/include/lldb/Utility/Flags.h
+++ lldb/include/lldb/Utility/Flags.h
@@ -121,32 +121,6 @@
/// \b true if \a bit is 0, \b false otherwise.
bool IsClear(ValueType bit) const { return (m_flags & bit) == 0; }
- /// Get the number of zero bits in \a m_flags.
- ///
- /// \return
- /// The number of bits that are set to 0 in the current flags.
- size_t ClearCount() const {
- size_t count = 0;
- for (ValueType shift = 0; shift < sizeof(ValueType) * 8; ++shift) {
- if ((m_flags & (1u << shift)) == 0)
- ++count;
- }
- return count;
- }
-
- /// Get the number of one bits in \a m_flags.
- ///
- /// \return
- /// The number of bits that are set to 1 in the current flags.
- size_t SetCount() const {
- size_t count = 0;
- for (ValueType mask = m_flags; mask; mask >>= 1) {
- if (mask & 1u)
- ++count;
- }
- return count;
- }
-
protected:
ValueType m_flags; ///< The flags.
};
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits