Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-02-25 06:12:19 +0300
committerAnna Henningsen <anna@addaleax.net>2019-03-01 23:57:54 +0300
commit31975bbc88d353cf2eecc93c9d2cde62dba67b2c (patch)
tree7a91545cfd50182e50addd1aa3a6468d74f65474 /src/string_decoder.cc
parentb42dcb0eeb2d2c302b0ecabbc1092605a54213d6 (diff)
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/string_decoder.cc')
-rw-r--r--src/string_decoder.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/string_decoder.cc b/src/string_decoder.cc
index 9cf1bd671b3..1441ca86936 100644
--- a/src/string_decoder.cc
+++ b/src/string_decoder.cc
@@ -4,6 +4,7 @@
#include "string_decoder-inl.h"
using v8::Array;
+using v8::ArrayBufferView;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Integer;
@@ -252,9 +253,13 @@ void DecodeData(const FunctionCallbackInfo<Value>& args) {
StringDecoder* decoder =
reinterpret_cast<StringDecoder*>(Buffer::Data(args[0]));
CHECK_NOT_NULL(decoder);
- size_t nread = Buffer::Length(args[1]);
+
+ CHECK(args[1]->IsArrayBufferView());
+ ArrayBufferViewContents<char> content(args[1].As<ArrayBufferView>());
+ size_t length = content.length();
+
MaybeLocal<String> ret =
- decoder->DecodeData(args.GetIsolate(), Buffer::Data(args[1]), &nread);
+ decoder->DecodeData(args.GetIsolate(), content.data(), &length);
if (!ret.IsEmpty())
args.GetReturnValue().Set(ret.ToLocalChecked());
}