/// all - Returns true if all bits are set.
bool all() const {
- // TODO: Optimize this.
- return count() == size();
+ if (empty())
+ return true;
+
+ for (unsigned i = 0; i < NumBitWords(size()) - 1; ++i)
+ if (Bits[i] != ~0UL)
+ return false;
+
+ // For the last word check that the lower bits are ones. The unused bits are
+ // always zero.
+ return Bits[NumBitWords(size()) - 1] == ~(~0UL << (Size % BITWORD_SIZE));
}
/// none - Returns true if none of the bits are set.
EXPECT_TRUE(Vec.none());
EXPECT_FALSE(Vec.empty());
+ Vec.flip();
+ EXPECT_EQ(130U, Vec.count());
+ EXPECT_EQ(130U, Vec.size());
+ EXPECT_TRUE(Vec.any());
+ EXPECT_TRUE(Vec.all());
+ EXPECT_FALSE(Vec.none());
+ EXPECT_FALSE(Vec.empty());
+
Inv = TypeParam().flip();
EXPECT_EQ(0U, Inv.count());
EXPECT_EQ(0U, Inv.size());