Title: [170938] trunk/Source/WebCore
- Revision
- 170938
- Author
- psola...@apple.com
- Date
- 2014-07-09 17:18:17 -0700 (Wed, 09 Jul 2014)
Log Message
Make SharedBuffer::append(SharedBuffer*) be smarter about CFData and data arrays
https://bugs.webkit.org/show_bug.cgi?id=134731
Reviewed by Antti Koivisto.
If the target SharedBuffer has a CFDataRef or a data array then we can simply retain that
CFDataRef or data array elements in the SharedBuffer being appended to. This avoids
unnecessary copying.
No new tests because no functional changes.
* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::append):
(WebCore::SharedBuffer::maybeAppendPlatformData):
* platform/SharedBuffer.h:
* platform/cf/SharedBufferCF.cpp:
(WebCore::SharedBuffer::maybeAppendPlatformData):
(WebCore::SharedBuffer::maybeAppendDataArray):
* platform/soup/SharedBufferSoup.cpp:
(WebCore::SharedBuffer::maybeAppendPlatformData):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (170937 => 170938)
--- trunk/Source/WebCore/ChangeLog 2014-07-09 23:48:26 UTC (rev 170937)
+++ trunk/Source/WebCore/ChangeLog 2014-07-10 00:18:17 UTC (rev 170938)
@@ -1,3 +1,26 @@
+2014-07-09 Pratik Solanki <psola...@apple.com>
+
+ Make SharedBuffer::append(SharedBuffer*) be smarter about CFData and data arrays
+ https://bugs.webkit.org/show_bug.cgi?id=134731
+
+ Reviewed by Antti Koivisto.
+
+ If the target SharedBuffer has a CFDataRef or a data array then we can simply retain that
+ CFDataRef or data array elements in the SharedBuffer being appended to. This avoids
+ unnecessary copying.
+
+ No new tests because no functional changes.
+
+ * platform/SharedBuffer.cpp:
+ (WebCore::SharedBuffer::append):
+ (WebCore::SharedBuffer::maybeAppendPlatformData):
+ * platform/SharedBuffer.h:
+ * platform/cf/SharedBufferCF.cpp:
+ (WebCore::SharedBuffer::maybeAppendPlatformData):
+ (WebCore::SharedBuffer::maybeAppendDataArray):
+ * platform/soup/SharedBufferSoup.cpp:
+ (WebCore::SharedBuffer::maybeAppendPlatformData):
+
2014-07-09 Brent Fulgham <bfulg...@apple.com>
[Win] Remove uses of 'bash' in build system
Modified: trunk/Source/WebCore/platform/SharedBuffer.cpp (170937 => 170938)
--- trunk/Source/WebCore/platform/SharedBuffer.cpp 2014-07-09 23:48:26 UTC (rev 170937)
+++ trunk/Source/WebCore/platform/SharedBuffer.cpp 2014-07-10 00:18:17 UTC (rev 170938)
@@ -296,6 +296,13 @@
void SharedBuffer::append(SharedBuffer* data)
{
+ if (maybeAppendPlatformData(data))
+ return;
+#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
+ if (maybeAppendDataArray(data))
+ return;
+#endif
+
const char* segment;
size_t position = 0;
while (size_t length = data->getSomeData(segment, position)) {
@@ -512,6 +519,11 @@
return 0;
}
+inline bool SharedBuffer::maybeAppendPlatformData(SharedBuffer*)
+{
+ return false;
+}
+
#endif
PassRefPtr<SharedBuffer> utf8Buffer(const String& string)
Modified: trunk/Source/WebCore/platform/SharedBuffer.h (170937 => 170938)
--- trunk/Source/WebCore/platform/SharedBuffer.h 2014-07-09 23:48:26 UTC (rev 170937)
+++ trunk/Source/WebCore/platform/SharedBuffer.h 2014-07-10 00:18:17 UTC (rev 170938)
@@ -189,6 +189,7 @@
void clearPlatformData();
void maybeTransferPlatformData();
+ bool maybeAppendPlatformData(SharedBuffer*);
void copyBufferAndClear(char* destination, unsigned bytesToCopy) const;
@@ -201,6 +202,7 @@
mutable Vector<RetainPtr<CFDataRef>> m_dataArray;
unsigned copySomeDataFromDataArray(const char*& someData, unsigned position) const;
const char *singleDataArrayBuffer() const;
+ bool maybeAppendDataArray(SharedBuffer*);
#else
mutable Vector<char*> m_segments;
#endif
Modified: trunk/Source/WebCore/platform/cf/SharedBufferCF.cpp (170937 => 170938)
--- trunk/Source/WebCore/platform/cf/SharedBufferCF.cpp 2014-07-09 23:48:26 UTC (rev 170937)
+++ trunk/Source/WebCore/platform/cf/SharedBufferCF.cpp 2014-07-10 00:18:17 UTC (rev 170938)
@@ -112,6 +112,14 @@
m_cfData = newContents->m_cfData;
}
+bool SharedBuffer::maybeAppendPlatformData(SharedBuffer* newContents)
+{
+ if (size() || !newContents->m_cfData)
+ return false;
+ m_cfData = newContents->m_cfData;
+ return true;
+}
+
#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
PassRefPtr<SharedBuffer> SharedBuffer::wrapCFDataArray(CFArrayRef cfDataArray)
{
@@ -187,6 +195,19 @@
return reinterpret_cast<const char*>(CFDataGetBytePtr(m_dataArray.at(0).get()));
}
+
+bool SharedBuffer::maybeAppendDataArray(SharedBuffer* data)
+{
+ if (m_buffer.size() || m_cfData || !data->m_dataArray.size())
+ return false;
+#if !ASSERT_DISABLED
+ unsigned originalSize = size();
#endif
+ for (auto cfData : data->m_dataArray)
+ append(cfData.get());
+ ASSERT(size() == originalSize + data->size());
+ return true;
+}
+#endif
}
Modified: trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp (170937 => 170938)
--- trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp 2014-07-09 23:48:26 UTC (rev 170937)
+++ trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp 2014-07-10 00:18:17 UTC (rev 170938)
@@ -79,6 +79,11 @@
return m_soupBuffer->length;
}
+bool SharedBuffer::maybeAppendPlatformData(SharedBuffer*)
+{
+ return false;
+}
+
} // namespace WebCore
#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes