From 539ada62723c915e81e56cc691b21b2b8d08faee Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Fri, 12 Sep 2025 12:50:13 -0700 Subject: [PATCH] use ArrayBuffer->Data() when available This is faster than accessing the BackingStore. API is available in V8 10.5+ per https://github.com/nodejs/node/issues/32226#issuecomment-1185423020. It was backported to Node.js v18.8.0 in https://github.com/nodejs/node/commit/a0c57837c4d79b9bf45a65ee547043d46794b017, but Node.js minor versions can't be used as the basis for feature support. --- nan_typedarray_contents.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nan_typedarray_contents.h b/nan_typedarray_contents.h index f2650eda..c9323e23 100644 --- a/nan_typedarray_contents.h +++ b/nan_typedarray_contents.h @@ -31,9 +31,13 @@ class TypedArrayContents { v8::Local buffer = array->Buffer(); length = byte_length / sizeof(T); +#if (V8_MAJOR_VERSION >= 10 || \ + (V8_MAJOR_VERSION == 10 && \ + (defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 5))) + data = static_cast(buffer->Data()) + byte_offset; // Actually it's 7.9 here but this would lead to ABI issues with Node.js 13 // using 7.8 till 13.2.0. -#if (V8_MAJOR_VERSION >= 8) +#elif (V8_MAJOR_VERSION >= 8) data = static_cast(buffer->GetBackingStore()->Data()) + byte_offset; #else data = static_cast(buffer->GetContents().Data()) + byte_offset;