Title: [294750] trunk/Source/WTF/wtf/FastBitVector.cpp
Revision
294750
Author
[email protected]
Date
2022-05-24 09:15:40 -0700 (Tue, 24 May 2022)

Log 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

Modified Paths

Diff

Modified: trunk/Source/WTF/wtf/FastBitVector.cpp (294749 => 294750)


--- trunk/Source/WTF/wtf/FastBitVector.cpp	2022-05-24 16:14:21 UTC (rev 294749)
+++ trunk/Source/WTF/wtf/FastBitVector.cpp	2022-05-24 16:15:40 UTC (rev 294750)
@@ -34,8 +34,7 @@
 
 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::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;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to