perf: use ArrayBuffer::Data() instead of GetBackingStore()->Data() (#44073)

perf: use ArrayBuffer::Data() API

Replace our `GetBackingStore()->Data()` calls with this instead.
Explained by the V8 docs, ArrayBuffer.Data() is

> More efficient shortcut for GetBackingStore()->Data(). The
> returned pointer is valid as long as the ArrayBuffer is alive.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-10-01 13:52:00 -05:00 committed by GitHub
parent 0646cbfba6
commit 7b14a305f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 5 deletions

View file

@ -255,9 +255,7 @@ v8::Local<v8::Value> NativeImage::ToBitmap(gin::Arguments* args) {
auto array_buffer = auto array_buffer =
v8::ArrayBuffer::New(args->isolate(), info.computeMinByteSize()); v8::ArrayBuffer::New(args->isolate(), info.computeMinByteSize());
auto backing_store = array_buffer->GetBackingStore(); if (bitmap.readPixels(info, array_buffer->Data(), info.minRowBytes(), 0, 0)) {
if (bitmap.readPixels(info, backing_store->Data(), info.minRowBytes(), 0,
0)) {
return node::Buffer::New(args->isolate(), array_buffer, 0, return node::Buffer::New(args->isolate(), array_buffer, 0,
info.computeMinByteSize()) info.computeMinByteSize())
.ToLocalChecked(); .ToLocalChecked();

View file

@ -712,8 +712,7 @@ void SimpleURLLoaderWrapper::OnDataReceived(std::string_view string_view,
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
auto array_buffer = v8::ArrayBuffer::New(isolate, string_view.size()); auto array_buffer = v8::ArrayBuffer::New(isolate, string_view.size());
auto backing_store = array_buffer->GetBackingStore(); memcpy(array_buffer->Data(), string_view.data(), string_view.size());
memcpy(backing_store->Data(), string_view.data(), string_view.size());
Emit("data", array_buffer, Emit("data", array_buffer,
base::AdaptCallbackForRepeating(std::move(resume))); base::AdaptCallbackForRepeating(std::move(resume)));
} }