Skip to content
Permalink
Browse files
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
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294750 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed May 24, 2022
1 parent edadb60 commit 197387a9ffd21dfddc4c5ad87ae165cc8276c8d5
Showing 1 changed file with 7 additions and 7 deletions.
@@ -34,8 +34,7 @@ DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(FastBitVector);

void FastBitVectorWordOwner::setEqualsSlow(const FastBitVectorWordOwner& other)
{
uint32_t* newArray = static_cast<uint32_t*>(
FastBitVectorMalloc::zeroedMalloc(other.arrayLength() * sizeof(uint32_t)));
uint32_t* newArray = static_cast<uint32_t*>(FastBitVectorMalloc::malloc(other.arrayLength() * sizeof(uint32_t)));
memcpy(newArray, other.m_words, other.arrayLength() * sizeof(uint32_t));
if (m_words)
FastBitVectorMalloc::free(m_words);
@@ -46,14 +45,15 @@ void FastBitVectorWordOwner::setEqualsSlow(const FastBitVectorWordOwner& other)
void FastBitVectorWordOwner::resizeSlow(size_t numBits)
{
size_t newLength = fastBitVectorArrayLength(numBits);

RELEASE_ASSERT(newLength >= arrayLength());
size_t oldLength = arrayLength();
RELEASE_ASSERT(newLength >= oldLength);

// Use fastCalloc instead of fastRealloc because we expect the common
// Use fastMalloc instead of fastRealloc because we expect the common
// use case for this method to be initializing the size of the bitvector.

uint32_t* newArray = static_cast<uint32_t*>(FastBitVectorMalloc::zeroedMalloc(newLength * sizeof(uint32_t)));
memcpy(newArray, m_words, arrayLength() * sizeof(uint32_t));
uint32_t* newArray = static_cast<uint32_t*>(FastBitVectorMalloc::malloc(newLength * sizeof(uint32_t)));
memcpy(newArray, m_words, oldLength * sizeof(uint32_t));
memset(newArray + oldLength, 0, (newLength - oldLength) * sizeof(uint32_t));
if (m_words)
FastBitVectorMalloc::free(m_words);
m_words = newArray;

0 comments on commit 197387a

Please sign in to comment.