mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
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>
This commit is contained in:
8 files changed
+183
-145
No files matched your search
@@ -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());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user