diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-02-13 22:40:50 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-02-15 23:39:32 +0300 |
commit | a7c523e26df468782691c7e16b2e033c6256beb3 (patch) | |
tree | 33e01d937892b62c7b424ca4623b215b417d5567 /src/js_stream.cc | |
parent | 79296dc2d02c0b9872bbfcbb89148ea036a546d0 (diff) |
src: prefer 3-argument Array::New()
This is nicer, because:
1. It reduces overall code size,
2. It’s faster, because `Object::Set()` calls are relatively slow, and
3. It helps avoid invalid `.Check()`/`.FromJust()` calls.
PR-URL: https://github.com/nodejs/node/pull/31775
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/js_stream.cc')
-rw-r--r-- | src/js_stream.cc | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/js_stream.cc b/src/js_stream.cc index a67fd37dbdb..64941b1c4e4 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -116,16 +116,15 @@ int JSStream::DoWrite(WriteWrap* w, HandleScope scope(env()->isolate()); Context::Scope context_scope(env()->context()); - Local<Array> bufs_arr = Array::New(env()->isolate(), count); - Local<Object> buf; + MaybeStackBuffer<Local<Value>, 16> bufs_arr(count); for (size_t i = 0; i < count; i++) { - buf = Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked(); - bufs_arr->Set(env()->context(), i, buf).Check(); + bufs_arr[i] = + Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked(); } Local<Value> argv[] = { w->object(), - bufs_arr + Array::New(env()->isolate(), bufs_arr.out(), count) }; TryCatchScope try_catch(env()); |