[Cocoa] Teach SharedBuffer to return an NSArray of data segments to avoid flattening
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jan 2017 01:32:02 +0000 (01:32 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jan 2017 01:32:02 +0000 (01:32 +0000)
commita83be96c1ddf2299e6613ef246ddf05f6ec105bc
tree1d2c72e82d03b7be13cadd5def9fb400dfd06be6
parent719655a7f0fcc813e024b07487b700b514ac822f
[Cocoa] Teach SharedBuffer to return an NSArray of data segments to avoid flattening
https://bugs.webkit.org/show_bug.cgi?id=166696

Reviewed by Tim Horton.

Source/WebCore:

Existing methods of extracting NSData from a SharedBuffer require either merging or copying
data segments. Since data segments are stored in CFDataRefs on Cocoa platforms, it should be
possible to retrieve an NSArray of the segments without having to first flatten to a single
buffer.

This patch implements such a method. This will be used in a follow-on patch, where I will
need to pass SharedBuffer data to QuickLook via an NSArray of NSData.

New API test: SharedBufferTest.createNSDataArray.

* platform/SharedBuffer.h: Declared createNSArrayData(), and exported two functions needed
by the API test.
* platform/cocoa/SharedBufferCocoa.mm:
(WebCore::SharedBuffer::createNSDataArray): Added. Returns m_cfData or a copy of m_fileData
if either exist. Otherwise, adds m_buffer (wrapped in a WebCoreSharedBufferData object) and
the objects in m_dataArray to a NSMutableArray and returns it.

Tools:

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/PlatformWin.cmake:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp: Moved class SharedBufferTest to SharedBufferTest.{cpp,h}.
* TestWebKitAPI/Tests/WebCore/SharedBufferTest.cpp: Moved class SharedBufferTest from SharedBuffer.cpp.
* TestWebKitAPI/Tests/WebCore/SharedBufferTest.h: Ditto.
* TestWebKitAPI/Tests/WebCore/cocoa/SharedBuffer.mm: Added.
(TestWebKitAPI::expectDataArraysEqual): Added a helper to assert that two NSArrays of NSData are equal.
(TestWebKitAPI::TEST_F): Added a test for createNSDataArray.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210310 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/platform/SharedBuffer.h
Source/WebCore/platform/cocoa/SharedBufferCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformGTK.cmake
Tools/TestWebKitAPI/PlatformWin.cmake
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp
Tools/TestWebKitAPI/Tests/WebCore/SharedBufferTest.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebCore/SharedBufferTest.h [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebCore/cocoa/SharedBuffer.mm [new file with mode: 0644]