Avoid resizing the internal buffer of SharedBuffer when creating a PurgeableBuffer
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2013 18:20:36 +0000 (18:20 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2013 18:20:36 +0000 (18:20 +0000)
commitdc1b68755cd101602c565f70aac6b081b1b25787
tree618e69584099f6147d57b1e063505571ff561e85
parentcd588667a37ae9d11ec1b6d2cb61ef927719d292
Avoid resizing the internal buffer of SharedBuffer when creating a PurgeableBuffer
https://bugs.webkit.org/show_bug.cgi?id=122516

Reviewed by Darin Adler.

Currently when we create a PurgeableBuffer from a SharedBuffer we may
resize the internal buffer of the SharedBuffer so that it can fit the
concatenated contents of all of its segments before copying this
internal buffer to the internal buffer of the PurgeableBuffer. Instead,
we can avoid resizing the internal buffer of SharedBuffer by allocating
a PurgeableBuffer and then copying the internal buffer of SharedBuffer
and its segments directly into it.

* platform/PurgeableBuffer.h:
(WebCore::PurgeableBuffer::createUninitialized): Add inline implementation
when building with ENABLE_PURGEABLE_MEMORY disabled.
* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::createPurgeableBuffer): Implemented in terms of
SharedBuffer::{copyBufferAndClear, createUninitialized}().
(WebCore::SharedBuffer::copyBufferAndClear): Added.
(WebCore::SharedBuffer::buffer): Moved logic to copy segments/data array to
SharedBuffer::copyBufferAndClear() and modified this function to use it.
* platform/SharedBuffer.h:
* platform/cf/SharedBufferCF.cpp:
(WebCore::SharedBuffer::copyBufferAndClear): Renamed; formerly called SharedBuffer::copyDataArrayAndClear.
* platform/mac/PurgeableBufferMac.cpp:
(WebCore::allocatePurgeableBuffer): Added.
(WebCore::PurgeableBuffer::createUninitialized): Added.
(WebCore::PurgeableBuffer::create): Moved logic to allocate a purgeable buffer into
PurgeableBuffer::createUninitialized() and modified this function to use it.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157235 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/platform/PurgeableBuffer.h
Source/WebCore/platform/SharedBuffer.cpp
Source/WebCore/platform/SharedBuffer.h
Source/WebCore/platform/cf/SharedBufferCF.cpp
Source/WebCore/platform/mac/PurgeableBufferMac.cpp