Skip to content

Commit 539ada6

Browse files
committed
use ArrayBuffer->Data() when available
This is faster than accessing the BackingStore. API is available in V8 10.5+ per nodejs/node#32226 (comment). It was backported to Node.js v18.8.0 in nodejs/node@a0c5783, but Node.js minor versions can't be used as the basis for feature support.
1 parent 675cefe commit 539ada6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

nan_typedarray_contents.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ class TypedArrayContents {
3131
v8::Local<v8::ArrayBuffer> buffer = array->Buffer();
3232

3333
length = byte_length / sizeof(T);
34+
#if (V8_MAJOR_VERSION >= 10 || \
35+
(V8_MAJOR_VERSION == 10 && \
36+
(defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 5)))
37+
data = static_cast<char*>(buffer->Data()) + byte_offset;
3438
// Actually it's 7.9 here but this would lead to ABI issues with Node.js 13
3539
// using 7.8 till 13.2.0.
36-
#if (V8_MAJOR_VERSION >= 8)
40+
#elif (V8_MAJOR_VERSION >= 8)
3741
data = static_cast<char*>(buffer->GetBackingStore()->Data()) + byte_offset;
3842
#else
3943
data = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;

0 commit comments

Comments
 (0)