Bug 102306 - For single element arrays use the pointer into the CFDataRef instead of copying data
Summary: For single element arrays use the pointer into the CFDataRef instead of copyi...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Pratik Solanki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2012-11-14 17:41 PST by Pratik Solanki
Modified: 2012-11-24 12:44 PST (History)
8 users (show)

See Also:


Attachments
Patch (3.91 KB, patch)
2012-11-15 10:49 PST, Pratik Solanki
no flags Details | Formatted Diff | Diff
Patch (8.06 KB, patch)
2012-11-15 17:31 PST, Pratik Solanki
ap: review+
Details | Formatted Diff | Diff
Be slightly nicer! (2.35 KB, patch)
2012-11-16 17:00 PST, Pratik Solanki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pratik Solanki 2012-11-14 17:41:48 PST
This is an optimization when USE(NETWORK_CFDATA_ARRAY_CALLBACK) is available. Generally, WebCore copies the data returned from CFNetwork into its own buffers once the resource is done loading. However, if the resource is cached, CFNetwork will return us a CFArrayRef with exactly 1 CFDataRef in it. In such a case, it might be beneficial to not copy the data and just use the byte pointer i.e. call CFDataGetBytePtr() and use that memory directly.
Comment 1 Pratik Solanki 2012-11-14 17:42:10 PST
<rdar://problem/12267471>
Comment 2 Pratik Solanki 2012-11-15 10:49:13 PST
Created attachment 174487 [details]
Patch
Comment 3 Pratik Solanki 2012-11-15 12:55:20 PST
Comment on attachment 174487 [details]
Patch

Retracting. This needs another tweak.
Comment 4 Pratik Solanki 2012-11-15 17:31:12 PST
Created attachment 174569 [details]
Patch
Comment 5 Alexey Proskuryakov 2012-11-15 17:38:02 PST
Comment on attachment 174569 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=174569&action=review

Looks reasonable to me. Brady might want to have a look too, as he's been refactoring adjacent code.

> Source/WebCore/ChangeLog:22
> +        (WebCore):

It is helpful to edit ChangeLogs to remove useless gunk like this. ChangeLogs are meant for human consumption, so anything you can do to make reading easier is a plus (but obviously, not hugely important for somethign trivial like this).

> Source/WebCore/platform/SharedBuffer.cpp:149
> +    const char *buffer = singleDataArrayBuffer();

Star goes to the left.

> Source/WebCore/platform/cf/SharedBufferCF.cpp:144
> +        return reinterpret_cast<const char *>(CFDataGetBytePtr(m_dataArray.at(0).get()));

Ditto.
Comment 6 Pratik Solanki 2012-11-16 12:39:45 PST
Thanks for the review. I'll commit with the changes suggested. I also had to change a variable name since the compiler got confused about buffer being a const char * and a member function.
Comment 7 Pratik Solanki 2012-11-16 12:47:47 PST
Committed r134987: <http://trac.webkit.org/changeset/134987>
Comment 8 Darin Adler 2012-11-16 14:51:15 PST
Comment on attachment 174569 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=174569&action=review

> Source/WebCore/platform/SharedBuffer.cpp:151
> +    const char *buffer = singleDataArrayBuffer();
> +    if (buffer)
> +        return buffer;

This would be slightly nicer with the variable definition inside the if.

> Source/WebCore/platform/cf/SharedBufferCF.cpp:143
> +    if (m_dataArray.size() == 1)

This would be slightly nicer as an early return.
Comment 9 Darin Adler 2012-11-16 14:52:08 PST
(In reply to comment #6)
> I also had to change a variable name since the compiler got confused about buffer being a const char * and a member function.

An alternate solution in cases like that is to use this->functionName syntax to call a member function that is shadowed by a same-named local variable. We like that because it lets us use the cleanest simplest names for both.
Comment 10 Pratik Solanki 2012-11-16 17:00:45 PST
Reopening to attach new patch.
Comment 11 Pratik Solanki 2012-11-16 17:00:46 PST
Created attachment 174785 [details]
Be slightly nicer!

Sounds good. Added a patch with the comments addressed
Comment 12 Brent Fulgham 2012-11-19 17:44:03 PST
Comment on attachment 174785 [details]
Be slightly nicer!

Since the Apple guys are on vacation, and you have executed the changes ap and Darin asked for, r=me.
Comment 13 WebKit Review Bot 2012-11-19 17:55:49 PST
Comment on attachment 174785 [details]
Be slightly nicer!

Clearing flags on attachment: 174785

Committed r135221: <http://trac.webkit.org/changeset/135221>
Comment 14 Pratik Solanki 2012-11-24 12:44:12 PST
Brent, thanks for the r+ and cq+. Marking this bug as fixed.