Changeset 262167 in webkit
- Timestamp:
- May 26, 2020, 4:33:09 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r262156 r262167 1 2020-05-26 Mark Lam <mark.lam@apple.com> 2 3 Enhance Bitmap::setEachNthBit() to also take an end index. 4 https://bugs.webkit.org/show_bug.cgi?id=212386 5 <rdar://problem/63643324> 6 7 Reviewed by Robin Morisset. 8 9 Previously, it was only taking the n interval, and the start index. 10 Also fixed isEmpty() and isFull() to return a bool instead of size_t. 11 12 * wtf/Bitmap.h: 13 (WTF::WordType>::isEmpty const): 14 (WTF::WordType>::isFull const): 15 (WTF::WordType>::setEachNthBit): 16 1 17 2020-05-26 Don Olmstead <don.olmstead@sony.com> 2 18 -
trunk/Source/WTF/wtf/Bitmap.h
r262030 r262167 59 59 int64_t findRunOfZeros(size_t runLength) const; 60 60 size_t count(size_t start = 0) const; 61 size_tisEmpty() const;62 size_tisFull() const;61 bool isEmpty() const; 62 bool isFull() const; 63 63 64 64 void merge(const Bitmap&); … … 120 120 void setAndClear(Bitmap&); 121 121 122 void setEachNthBit(size_t start, size_t n);122 void setEachNthBit(size_t n, size_t start = 0, size_t end = bitmapSize); 123 123 124 124 bool operator==(const Bitmap&) const; … … 294 294 295 295 template<size_t bitmapSize, typename WordType> 296 inline size_tBitmap<bitmapSize, WordType>::isEmpty() const296 inline bool Bitmap<bitmapSize, WordType>::isEmpty() const 297 297 { 298 298 for (size_t i = 0; i < words; ++i) … … 303 303 304 304 template<size_t bitmapSize, typename WordType> 305 inline size_tBitmap<bitmapSize, WordType>::isFull() const305 inline bool Bitmap<bitmapSize, WordType>::isFull() const 306 306 { 307 307 for (size_t i = 0; i < words; ++i) … … 431 431 432 432 template<size_t bitmapSize, typename WordType> 433 inline void Bitmap<bitmapSize, WordType>::setEachNthBit(size_t start, size_t n) 434 { 435 size_t index = start; 436 size_t wordIndex = index / wordSize; 437 index = index - wordIndex * wordSize; 438 while (wordIndex < words) { 433 inline void Bitmap<bitmapSize, WordType>::setEachNthBit(size_t n, size_t start, size_t end) 434 { 435 ASSERT(start <= end); 436 ASSERT(end <= bitmapSize); 437 438 size_t wordIndex = start / wordSize; 439 size_t endWordIndex = end / wordSize; 440 size_t index = start - wordIndex * wordSize; 441 while (wordIndex < endWordIndex) { 439 442 while (index < wordSize) { 440 443 bits[wordIndex] |= (one << index); … … 444 447 wordIndex++; 445 448 } 449 450 size_t endIndex = end - endWordIndex * wordSize; 451 while (index < endIndex) { 452 bits[wordIndex] |= (one << index); 453 index += n; 454 } 455 446 456 if constexpr (!!(bitmapSize % wordSize)) { 447 457 constexpr size_t remainingBits = bitmapSize % wordSize; -
trunk/Tools/ChangeLog
r262158 r262167 1 2020-05-26 Mark Lam <mark.lam@apple.com> 2 3 Enhance Bitmap::setEachNthBit() to also take an end index. 4 https://bugs.webkit.org/show_bug.cgi?id=212386 5 <rdar://problem/63643324> 6 7 Reviewed by Robin Morisset. 8 9 * TestWebKitAPI/Tests/WTF/Bitmap.cpp: 10 (TestWebKitAPI::testBitmapSetEachNthBitImpl): 11 1 12 2020-05-26 Fujii Hironori <Hironori.Fujii@sony.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WTF/Bitmap.cpp
r262034 r262167 982 982 983 983 EXPECT_TRUE(temp == zeroes); 984 temp.setEachNthBit( 0,1);984 temp.setEachNthBit(1); 985 985 EXPECT_TRUE(temp == ones); 986 986 … … 988 988 size_t nValuesCount = sizeof(nValues) / sizeof(nValues[0]); 989 989 990 for (size_t start = 0; start < wordSize; ++start) { 991 for (size_t j = 0; j < nValuesCount; ++j) { 992 size_t n = nValues[j]; 993 temp.clearAll(); 994 temp.setEachNthBit(start, n); 995 996 for (size_t i = 0; i < start; ++i) 997 EXPECT_FALSE(temp.get(i)); 998 999 size_t count = 0; 1000 for (size_t i = start; i < size; ++i) { 1001 bool expected = !count; 1002 EXPECT_TRUE(temp.get(i) == expected); 1003 count++; 1004 count = count % n; 990 size_t startEndValues[] = { 0, 1, 2, wordSize / 2, wordSize - 1, wordSize, size / 2, size - 1, size }; 991 constexpr size_t numberOfStartEndValues = sizeof(startEndValues) / sizeof(startEndValues[0]); 992 993 for (size_t start = 0; start < numberOfStartEndValues; ++start) { 994 for (size_t end = start; end < numberOfStartEndValues; ++end) { 995 size_t startIndex = startEndValues[start]; 996 size_t endIndex = startEndValues[end]; 997 if (endIndex < startIndex) 998 continue; 999 if (startIndex > size) 1000 continue; 1001 if (endIndex > size) 1002 continue; 1003 1004 for (size_t j = 0; j < nValuesCount; ++j) { 1005 size_t n = nValues[j]; 1006 temp.clearAll(); 1007 temp.setEachNthBit(n, startIndex, endIndex); 1008 1009 for (size_t i = 0; i < startIndex; ++i) 1010 EXPECT_FALSE(temp.get(i)); 1011 1012 size_t count = 0; 1013 for (size_t i = startIndex; i < endIndex; ++i) { 1014 bool expected = !count; 1015 EXPECT_TRUE(temp.get(i) == expected); 1016 count++; 1017 count = count % n; 1018 } 1019 1020 for (size_t i = endIndex; i < size; ++i) 1021 EXPECT_FALSE(temp.get(i)); 1005 1022 } 1006 1023 }
Note:
See TracChangeset
for help on using the changeset viewer.