⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 294750 in webkit


Ignore:
Timestamp:
May 24, 2022, 9:15:40 AM (4 years ago)
Author:
Chris Dumez
Message:

Avoid unnecessary calls to fastZeroedMalloc() in FastBitVector
https://bugs.webkit.org/show_bug.cgi?id=240812

Reviewed by Yusuke Suzuki.

We were calling fastZeroedMalloc() which would allocate the memory and memset it to 0,
only to then overwrite all (or most) of that memory with memcpy().

  • Source/WTF/wtf/FastBitVector.cpp:

(WTF::FastBitVectorWordOwner::setEqualsSlow):
(WTF::FastBitVectorWordOwner::resizeSlow):

Canonical link: https://commits.webkit.org/250918@main

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/wtf/FastBitVector.cpp

    r271921 r294750  
    3535void FastBitVectorWordOwner::setEqualsSlow(const FastBitVectorWordOwner& other)
    3636{
    37     uint32_t* newArray = static_cast<uint32_t*>(
    38         FastBitVectorMalloc::zeroedMalloc(other.arrayLength() * sizeof(uint32_t)));
     37    uint32_t* newArray = static_cast<uint32_t*>(FastBitVectorMalloc::malloc(other.arrayLength() * sizeof(uint32_t)));
    3938    memcpy(newArray, other.m_words, other.arrayLength() * sizeof(uint32_t));
    4039    if (m_words)
     
    4746{
    4847    size_t newLength = fastBitVectorArrayLength(numBits);
    49 
    50     RELEASE_ASSERT(newLength >= arrayLength());
     48    size_t oldLength = arrayLength();
     49    RELEASE_ASSERT(newLength >= oldLength);
    5150   
    52     // Use fastCalloc instead of fastRealloc because we expect the common
     51    // Use fastMalloc instead of fastRealloc because we expect the common
    5352    // use case for this method to be initializing the size of the bitvector.
    5453   
    55     uint32_t* newArray = static_cast<uint32_t*>(FastBitVectorMalloc::zeroedMalloc(newLength * sizeof(uint32_t)));
    56     memcpy(newArray, m_words, arrayLength() * sizeof(uint32_t));
     54    uint32_t* newArray = static_cast<uint32_t*>(FastBitVectorMalloc::malloc(newLength * sizeof(uint32_t)));
     55    memcpy(newArray, m_words, oldLength * sizeof(uint32_t));
     56    memset(newArray + oldLength, 0, (newLength - oldLength) * sizeof(uint32_t));
    5757    if (m_words)
    5858        FastBitVectorMalloc::free(m_words);
Note: See TracChangeset for help on using the changeset viewer.