Bug 236749 - Unnecessary copy/memory allocation
Summary: Unnecessary copy/memory allocation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jean-Yves Avenard [:jya]
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-16 20:21 PST by Jean-Yves Avenard [:jya]
Modified: 2022-02-17 15:27 PST (History)
3 users (show)

See Also:


Attachments
Patch (1.73 KB, patch)
2022-02-16 20:39 PST, Jean-Yves Avenard [:jya]
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Avenard [:jya] 2022-02-16 20:21:00 PST
We see:
Source/WebKitLegacy/mac/WebView/WebHTMLView.mm

https://github.com/WebKit/WebKit/blob/f0427c65db487c75295c5bd757777cb5d9049030/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm#L3544-L3547

```
    if (auto* image = hitTestResult.image()) {
        if (RefPtr<WebCore::FragmentedSharedBuffer> buffer = image->data())
            [items addObject:adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:buffer->makeContiguous()->data() length:buffer->size()]]).get()];
    }
```

we can create a NSData from the SharedBuffer directly, removing the need for the memory allocation and copy.
Comment 1 Radar WebKit Bug Importer 2022-02-16 20:21:50 PST
<rdar://problem/89064893>
Comment 2 Jean-Yves Avenard [:jya] 2022-02-16 20:39:01 PST
Created attachment 452300 [details]
Patch
Comment 3 EWS 2022-02-17 15:27:03 PST
Committed r290082 (247438@main): <https://commits.webkit.org/247438@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 452300 [details].