SkASSERT(numberOfBits > 0);
// Round up size to 32-bit boundary.
fDwordCount = (numberOfBits + 31) / 32;
- fBitData.set(malloc(fDwordCount * sizeof(uint32_t)));
- clearAll();
+ fBitData.set(sk_calloc_throw(fDwordCount * sizeof(uint32_t)));
}
SkBitSet::SkBitSet(const SkBitSet& source)
fBitCount = rhs.fBitCount;
fBitData.free();
fDwordCount = rhs.fDwordCount;
- fBitData.set(malloc(fDwordCount * sizeof(uint32_t)));
+ fBitData.set(sk_malloc_throw(fDwordCount * sizeof(uint32_t)));
memcpy(fBitData.get(), rhs.fBitData.get(), fDwordCount * sizeof(uint32_t));
return *this;
}
}
}
-void SkBitSet::setBit(int index, bool value) {
- uint32_t mask = 1 << (index % 32);
- if (value) {
- *(internalGet(index)) |= mask;
- } else {
- *(internalGet(index)) &= ~mask;
- }
-}
-
-bool SkBitSet::isBitSet(int index) const {
- uint32_t mask = 1 << (index % 32);
- return 0 != (*internalGet(index) & mask);
-}
-
bool SkBitSet::orBits(const SkBitSet& source) {
if (fBitCount != source.fBitCount) {
return false;
}
- uint32_t* targetBitmap = internalGet(0);
+ uint32_t* targetBitmap = this->internalGet(0);
uint32_t* sourceBitmap = source.internalGet(0);
for (size_t i = 0; i < fDwordCount; ++i) {
targetBitmap[i] |= sourceBitmap[i];
/** Set the value of the index-th bit.
*/
- void setBit(int index, bool value);
+ void setBit(int index, bool value) {
+ uint32_t mask = 1 << (index & 31);
+ uint32_t* chunk = this->internalGet(index);
+ if (value) {
+ *chunk |= mask;
+ } else {
+ *chunk &= ~mask;
+ }
+ }
/** Test if bit index is set.
*/
- bool isBitSet(int index) const;
+ bool isBitSet(int index) const {
+ uint32_t mask = 1 << (index & 31);
+ return SkToBool(*this->internalGet(index) & mask);
+ }
/** Or bits from source. false is returned if this doesn't have the same
* bit count as source.