Skip to content

Commit 905e787

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) and was backported to Node.js v18.8.0 in nodejs/node@a0c5783.
1 parent 675cefe commit 905e787

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

nan_typedarray_contents.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ 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+
(NODE_MAJOR_VERSION == 18 && NODE_MINOR_VERSION >= 8))
38+
data = static_cast<char*>(buffer->Data()) + byte_offset;
3439
// Actually it's 7.9 here but this would lead to ABI issues with Node.js 13
3540
// using 7.8 till 13.2.0.
36-
#if (V8_MAJOR_VERSION >= 8)
41+
#elif (V8_MAJOR_VERSION >= 8)
3742
data = static_cast<char*>(buffer->GetBackingStore()->Data()) + byte_offset;
3843
#else
3944
data = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;

0 commit comments

Comments
 (0)