From 7b14a305f878ae11664354ffb6df54bee16727c1 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 13:52:00 -0500 Subject: [PATCH] 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 --- shell/common/api/electron_api_native_image.cc | 4 +--- shell/common/api/electron_api_url_loader.cc | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/shell/common/api/electron_api_native_image.cc b/shell/common/api/electron_api_native_image.cc index de9efadaea48..f1a9eb11ab27 100644 --- a/shell/common/api/electron_api_native_image.cc +++ b/shell/common/api/electron_api_native_image.cc @@ -255,9 +255,7 @@ v8::Local NativeImage::ToBitmap(gin::Arguments* args) { auto array_buffer = v8::ArrayBuffer::New(args->isolate(), info.computeMinByteSize()); - auto backing_store = array_buffer->GetBackingStore(); - if (bitmap.readPixels(info, backing_store->Data(), info.minRowBytes(), 0, - 0)) { + if (bitmap.readPixels(info, array_buffer->Data(), info.minRowBytes(), 0, 0)) { return node::Buffer::New(args->isolate(), array_buffer, 0, info.computeMinByteSize()) .ToLocalChecked(); diff --git a/shell/common/api/electron_api_url_loader.cc b/shell/common/api/electron_api_url_loader.cc index 2d539e0652ab..9a7e8996a00b 100644 --- a/shell/common/api/electron_api_url_loader.cc +++ b/shell/common/api/electron_api_url_loader.cc @@ -712,8 +712,7 @@ void SimpleURLLoaderWrapper::OnDataReceived(std::string_view string_view, v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); auto array_buffer = v8::ArrayBuffer::New(isolate, string_view.size()); - auto backing_store = array_buffer->GetBackingStore(); - memcpy(backing_store->Data(), string_view.data(), string_view.size()); + memcpy(array_buffer->Data(), string_view.data(), string_view.size()); Emit("data", array_buffer, base::AdaptCallbackForRepeating(std::move(resume))); }