From 058a616135462a589ce7f01e3918918932a3ea1b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 2 Oct 2024 15:37:54 -0500 Subject: [PATCH] perf: use ArrayBuffer::Data() instead of GetBackingStore()->Data() (32-x-y) (#44095) perf: use ArrayBuffer::Data() instead of GetBackingStore()->Data() (#44067) 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. --- 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 e186d4ce2621..d6791dce499d 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 c8f40e45a328..8f91198d6c18 100644 --- a/shell/common/api/electron_api_url_loader.cc +++ b/shell/common/api/electron_api_url_loader.cc @@ -710,8 +710,7 @@ void SimpleURLLoaderWrapper::OnDataReceived(std::string_view string_piece, v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); auto array_buffer = v8::ArrayBuffer::New(isolate, string_piece.size()); - auto backing_store = array_buffer->GetBackingStore(); - memcpy(backing_store->Data(), string_piece.data(), string_piece.size()); + memcpy(array_buffer->Data(), string_piece.data(), string_piece.size()); Emit("data", array_buffer, base::AdaptCallbackForRepeating(std::move(resume))); }