Commit 262a9905 authored by psolanki@apple.com's avatar psolanki@apple.com

SharedBuffer m_segments and m_dataArray must be exclusive

https://bugs.webkit.org/show_bug.cgi?id=77715

Patch by Pratik Solanki <pratik.solanki@gmail.com> on 2013-08-29
Reviewed by Benjamin Poulain.

When USE(NETWORK_CFDATA_ARRAY_CALLBACK) is enabled, we use m_dataArray to hold the incoming
data. We do not use m_segments. Since they are exclusive in practice, do not define or use
m_segments when NETWORK_CFDATA_ARRAY_CALLBACK is enabled.

No new tests because no functional changes.

* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::append):
(WebCore::SharedBuffer::clear):
(WebCore::SharedBuffer::copy):
(WebCore::SharedBuffer::buffer):
(WebCore::SharedBuffer::getSomeData):
* platform/SharedBuffer.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154823 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5b4714c6
2013-08-29 Pratik Solanki <pratik.solanki@gmail.com>
SharedBuffer m_segments and m_dataArray must be exclusive
https://bugs.webkit.org/show_bug.cgi?id=77715
Reviewed by Benjamin Poulain.
When USE(NETWORK_CFDATA_ARRAY_CALLBACK) is enabled, we use m_dataArray to hold the incoming
data. We do not use m_segments. Since they are exclusive in practice, do not define or use
m_segments when NETWORK_CFDATA_ARRAY_CALLBACK is enabled.
No new tests because no functional changes.
* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::append):
(WebCore::SharedBuffer::clear):
(WebCore::SharedBuffer::copy):
(WebCore::SharedBuffer::buffer):
(WebCore::SharedBuffer::getSomeData):
* platform/SharedBuffer.h:
2013-08-29 Daniel Bates <dabates@apple.com>
[iOS] Upstream changes to WebCore/style
......@@ -171,7 +171,8 @@ void SharedBuffer::append(const char* data, unsigned length)
return;
maybeTransferPlatformData();
#if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
unsigned positionInSegment = offsetInSegment(m_size - m_buffer.size());
m_size += length;
......@@ -204,6 +205,12 @@ void SharedBuffer::append(const char* data, unsigned length)
m_segments.append(segment);
bytesToCopy = min(length, segmentSize);
}
#else
m_size += length;
if (m_buffer.isEmpty())
m_buffer.reserveInitialCapacity(length);
m_buffer.append(data, length);
#endif
}
void SharedBuffer::append(const Vector<char>& data)
......@@ -215,17 +222,18 @@ void SharedBuffer::clear()
{
clearPlatformData();
#if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
for (unsigned i = 0; i < m_segments.size(); ++i)
freeSegment(m_segments[i]);
m_segments.clear();
m_size = 0;
#else
m_dataArray.clear();
#endif
m_size = 0;
m_buffer.clear();
m_purgeableBuffer.clear();
#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
m_dataArray.clear();
#endif
}
PassRefPtr<SharedBuffer> SharedBuffer::copy() const
......@@ -239,8 +247,13 @@ PassRefPtr<SharedBuffer> SharedBuffer::copy() const
clone->m_size = m_size;
clone->m_buffer.reserveCapacity(m_size);
clone->m_buffer.append(m_buffer.data(), m_buffer.size());
#if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
for (unsigned i = 0; i < m_segments.size(); ++i)
clone->m_buffer.append(m_segments[i], segmentSize);
#else
for (unsigned i = 0; i < m_dataArray.size(); ++i)
clone->append(m_dataArray[i].get());
#endif
return clone;
}
......@@ -257,6 +270,7 @@ const Vector<char>& SharedBuffer::buffer() const
m_buffer.resize(m_size);
char* destination = m_buffer.data() + bufferSize;
unsigned bytesLeft = m_size - bufferSize;
#if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
for (unsigned i = 0; i < m_segments.size(); ++i) {
unsigned bytesToCopy = min(bytesLeft, segmentSize);
memcpy(destination, m_segments[i], bytesToCopy);
......@@ -265,7 +279,7 @@ const Vector<char>& SharedBuffer::buffer() const
freeSegment(m_segments[i]);
}
m_segments.clear();
#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
#else
copyDataArrayAndClear(destination, bytesLeft);
#endif
}
......@@ -294,6 +308,7 @@ unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con
}
position -= consecutiveSize;
#if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
unsigned segments = m_segments.size();
unsigned maxSegmentedSize = segments * segmentSize;
unsigned segment = segmentIndex(position);
......@@ -305,13 +320,10 @@ unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con
someData = m_segments[segment] + positionInSegment;
return segment == segments - 1 ? segmentedSize - position : segmentSize - positionInSegment;
}
#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
ASSERT(maxSegmentedSize <= position);
position -= maxSegmentedSize;
return copySomeDataFromDataArray(someData, position);
#else
ASSERT_NOT_REACHED();
return 0;
#else
return copySomeDataFromDataArray(someData, position);
#endif
}
......
......@@ -137,13 +137,14 @@ private:
unsigned m_size;
mutable Vector<char> m_buffer;
mutable Vector<char*> m_segments;
mutable OwnPtr<PurgeableBuffer> m_purgeableBuffer;
#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
mutable Vector<RetainPtr<CFDataRef> > m_dataArray;
void copyDataArrayAndClear(char *destination, unsigned bytesToCopy) const;
unsigned copySomeDataFromDataArray(const char*& someData, unsigned position) const;
const char *singleDataArrayBuffer() const;
#else
mutable Vector<char*> m_segments;
#endif
#if USE(CF)
explicit SharedBuffer(CFDataRef);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment