llvm.org GIT mirror llvm / 597253d
Optimize BitVector::all(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183521 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 6 years ago
2 changed file(s) with 18 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
137137
138138 /// all - Returns true if all bits are set.
139139 bool all() const {
140 // TODO: Optimize this.
141 return count() == size();
140 if (empty())
141 return true;
142
143 for (unsigned i = 0; i < NumBitWords(size()) - 1; ++i)
144 if (Bits[i] != ~0UL)
145 return false;
146
147 // For the last word check that the lower bits are ones. The unused bits are
148 // always zero.
149 return Bits[NumBitWords(size()) - 1] == ~(~0UL << (Size % BITWORD_SIZE));
142150 }
143151
144152 /// none - Returns true if none of the bits are set.
140140 EXPECT_TRUE(Vec.none());
141141 EXPECT_FALSE(Vec.empty());
142142
143 Vec.flip();
144 EXPECT_EQ(130U, Vec.count());
145 EXPECT_EQ(130U, Vec.size());
146 EXPECT_TRUE(Vec.any());
147 EXPECT_TRUE(Vec.all());
148 EXPECT_FALSE(Vec.none());
149 EXPECT_FALSE(Vec.empty());
150
143151 Inv = TypeParam().flip();
144152 EXPECT_EQ(0U, Inv.count());
145153 EXPECT_EQ(0U, Inv.size());