summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-02-25 04:12:19 +0100
committerAnna Henningsen <anna@addaleax.net>2019-03-01 21:57:54 +0100
commit31975bbc88d353cf2eecc93c9d2cde62dba67b2c (patch)
tree7a91545cfd50182e50addd1aa3a6468d74f65474 /src/util.cc
parentb42dcb0eeb2d2c302b0ecabbc1092605a54213d6 (diff)
downloadnode-new-31975bbc88d353cf2eecc93c9d2cde62dba67b2c.tar.gz
src: allow not materializing ArrayBuffers from C++
Where appropriate, use a helper that wraps around `ArrayBufferView::Buffer()` or `ArrayBufferView::CopyContents()` rather than `Buffer::Data()`, as that may help to avoid materializing the underlying `ArrayBuffer` when reading small typed arrays from C++. This allows keeping the performance benefits of the faster creation of heap-allocated small typed arrays in many cases. PR-URL: https://github.com/nodejs/node/pull/26301 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/util.cc b/src/util.cc
index 3cdc222a96..223e0e8772 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -29,6 +29,7 @@
namespace node {
+using v8::ArrayBufferView;
using v8::Isolate;
using v8::Local;
using v8::String;
@@ -89,11 +90,11 @@ BufferValue::BufferValue(Isolate* isolate, Local<Value> value) {
if (value->IsString()) {
MakeUtf8String(isolate, value, this);
- } else if (Buffer::HasInstance(value)) {
- const size_t len = Buffer::Length(value);
+ } else if (value->IsArrayBufferView()) {
+ const size_t len = value.As<ArrayBufferView>()->ByteLength();
// Leave place for the terminating '\0' byte.
AllocateSufficientStorage(len + 1);
- memcpy(out(), Buffer::Data(value), len);
+ value.As<ArrayBufferView>()->CopyContents(out(), len);
SetLengthAndZeroTerminate(len);
} else {
Invalidate();