diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-02-13 22:40:50 +0300 |
---|---|---|
committer | Shelley Vohr <shelley.vohr@gmail.com> | 2020-02-27 19:45:37 +0300 |
commit | 57302f866e9ba954992ac32334b6dad3ebd4090f (patch) | |
tree | 1ee3a18e814d1928f1feeff43bacf3d219dfa26a /src/node_file.cc | |
parent | db291aaf065d5b96cf179f74be7bafb4d1023a6e (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/node_file.cc')
-rw-r--r-- | src/node_file.cc | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/node_file.cc b/src/node_file.cc index ddba9ad42cc..360f20e5f6c 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -700,16 +700,11 @@ void AfterScanDirWithTypes(uv_fs_t* req) { type_v.emplace_back(Integer::New(isolate, ent.type)); } - Local<Array> result = Array::New(isolate, 2); - result->Set(env->context(), - 0, - Array::New(isolate, name_v.data(), - name_v.size())).Check(); - result->Set(env->context(), - 1, - Array::New(isolate, type_v.data(), - type_v.size())).Check(); - req_wrap->Resolve(result); + Local<Value> result[] = { + Array::New(isolate, name_v.data(), name_v.size()), + Array::New(isolate, type_v.data(), type_v.size()) + }; + req_wrap->Resolve(Array::New(isolate, result, arraysize(result))); } void Access(const FunctionCallbackInfo<Value>& args) { @@ -1519,13 +1514,11 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) { Local<Array> names = Array::New(isolate, name_v.data(), name_v.size()); if (with_types) { - Local<Array> result = Array::New(isolate, 2); - result->Set(env->context(), 0, names).Check(); - result->Set(env->context(), - 1, - Array::New(isolate, type_v.data(), - type_v.size())).Check(); - args.GetReturnValue().Set(result); + Local<Value> result[] = { + names, + Array::New(isolate, type_v.data(), type_v.size()) + }; + args.GetReturnValue().Set(Array::New(isolate, result, arraysize(result))); } else { args.GetReturnValue().Set(names); } |