Bug 236749

Summary: Unnecessary copy/memory allocation
Product: WebKit Reporter: Jean-Yves Avenard [:jya] <jean-yves.avenard>
Component: Page LoadingAssignee: Jean-Yves Avenard [:jya] <jean-yves.avenard>
Status: RESOLVED FIXED    
Severity: Normal CC: beidson, dino, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

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].