Changeset 262167 in webkit


Ignore:
Timestamp:
May 26, 2020, 4:33:09 PM (5 years ago)
Author:
mark.lam@apple.com
Message:

Enhance Bitmap::setEachNthBit() to also take an end index.
https://bugs.webkit.org/show_bug.cgi?id=212386
<rdar://problem/63643324>

Reviewed by Robin Morisset.

Source/WTF:

Previously, it was only taking the n interval, and the start index.
Also fixed isEmpty() and isFull() to return a bool instead of size_t.

  • wtf/Bitmap.h:

(WTF::WordType>::isEmpty const):
(WTF::WordType>::isFull const):
(WTF::WordType>::setEachNthBit):

Tools:

  • TestWebKitAPI/Tests/WTF/Bitmap.cpp:

(TestWebKitAPI::testBitmapSetEachNthBitImpl):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r262156 r262167  
     12020-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
    1172020-05-26  Don Olmstead  <don.olmstead@sony.com>
    218
  • trunk/Source/WTF/wtf/Bitmap.h

    r262030 r262167  
    5959    int64_t findRunOfZeros(size_t runLength) const;
    6060    size_t count(size_t start = 0) const;
    61     size_t isEmpty() const;
    62     size_t isFull() const;
     61    bool isEmpty() const;
     62    bool isFull() const;
    6363   
    6464    void merge(const Bitmap&);
     
    120120    void setAndClear(Bitmap&);
    121121
    122     void setEachNthBit(size_t start, size_t n);
     122    void setEachNthBit(size_t n, size_t start = 0, size_t end = bitmapSize);
    123123
    124124    bool operator==(const Bitmap&) const;
     
    294294
    295295template<size_t bitmapSize, typename WordType>
    296 inline size_t Bitmap<bitmapSize, WordType>::isEmpty() const
     296inline bool Bitmap<bitmapSize, WordType>::isEmpty() const
    297297{
    298298    for (size_t i = 0; i < words; ++i)
     
    303303
    304304template<size_t bitmapSize, typename WordType>
    305 inline size_t Bitmap<bitmapSize, WordType>::isFull() const
     305inline bool Bitmap<bitmapSize, WordType>::isFull() const
    306306{
    307307    for (size_t i = 0; i < words; ++i)
     
    431431
    432432template<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) {
     433inline 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) {
    439442        while (index < wordSize) {
    440443            bits[wordIndex] |= (one << index);
     
    444447        wordIndex++;
    445448    }
     449
     450    size_t endIndex = end - endWordIndex * wordSize;
     451    while (index < endIndex) {
     452        bits[wordIndex] |= (one << index);
     453        index += n;
     454    }
     455
    446456    if constexpr (!!(bitmapSize % wordSize)) {
    447457        constexpr size_t remainingBits = bitmapSize % wordSize;
  • trunk/Tools/ChangeLog

    r262158 r262167  
     12020-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
    1122020-05-26  Fujii Hironori  <Hironori.Fujii@sony.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WTF/Bitmap.cpp

    r262034 r262167  
    982982
    983983    EXPECT_TRUE(temp == zeroes);
    984     temp.setEachNthBit(0, 1);
     984    temp.setEachNthBit(1);
    985985    EXPECT_TRUE(temp == ones);
    986986
     
    988988    size_t nValuesCount = sizeof(nValues) / sizeof(nValues[0]);
    989989
    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));
    10051022            }
    10061023        }
Note: See TracChangeset for help on using the changeset viewer.