Merge pull request #2065 from js6i/bit-array-fix

Fix MVKBitArray::getIndexOfFirstSetBit() skipping over entries.
This commit is contained in:
Bill Hollings 2023-11-15 13:29:41 -05:00 committed by GitHub
commit abeed4e720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,7 +90,11 @@ public:
* and optionally clears that bit. If no bits are set, returns the size() of this bit array. * and optionally clears that bit. If no bits are set, returns the size() of this bit array.
*/ */
size_t getIndexOfFirstSetBit(size_t startIndex, bool shouldClear) { size_t getIndexOfFirstSetBit(size_t startIndex, bool shouldClear) {
size_t startSecIdx = std::max(getIndexOfSection(startIndex), _clearedSectionCount); size_t startSecIdx = getIndexOfSection(startIndex);
if (startSecIdx < _clearedSectionCount) {
startSecIdx = _clearedSectionCount;
startIndex = 0;
}
size_t bitIdx = startSecIdx << SectionMaskSize; size_t bitIdx = startSecIdx << SectionMaskSize;
size_t secCnt = getSectionCount(); size_t secCnt = getSectionCount();
for (size_t secIdx = startSecIdx; secIdx < secCnt; secIdx++) { for (size_t secIdx = startSecIdx; secIdx < secCnt; secIdx++) {
@ -101,6 +105,7 @@ public:
if (shouldClear) { clearBit(bitIdx); } if (shouldClear) { clearBit(bitIdx); }
return std::min(bitIdx, _bitCount); return std::min(bitIdx, _bitCount);
} }
startIndex = 0;
} }
return std::min(bitIdx, _bitCount); return std::min(bitIdx, _bitCount);
} }