diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-11-06 18:35:01 +0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-11-08 15:01:09 -0800 |
commit | c7e657908c4c2ade215ca51c04754b77489c760a (patch) | |
tree | 5d69e2dcc5bc605c707856834a2158ead963bb2e /src | |
parent | 00d368e5bc63a2009bd12932558eba71f0e1bc5a (diff) | |
download | android-node-v8-c7e657908c4c2ade215ca51c04754b77489c760a.tar.gz android-node-v8-c7e657908c4c2ade215ca51c04754b77489c760a.tar.bz2 android-node-v8-c7e657908c4c2ade215ca51c04754b77489c760a.zip |
fs: replace pushValueToArray with pure C++ API
Instead of calling into JS from C++ to push values into an array,
use the new Array::New API that takes a pointer and a length
directly.
PR-URL: https://github.com/nodejs/node/pull/24125
Refs: https://github.com/v8/v8/commit/0483e9a9abe77a73632fd85b9c0cd608efa9aa0d
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yang Guo <yangguo@chromium.org>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_file.cc | 74 |
1 files changed, 10 insertions, 64 deletions
diff --git a/src/node_file.cc b/src/node_file.cc index 920350f01a..6333f8d862 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -571,10 +571,7 @@ void AfterScanDir(uv_fs_t* req) { Environment* env = req_wrap->env(); Local<Value> error; int r; - Local<Array> names = Array::New(env->isolate(), 0); - Local<Function> fn = env->push_values_to_array_function(); - Local<Value> name_argv[NODE_PUSH_VAL_TO_ARRAY_MAX]; - size_t name_idx = 0; + std::vector<Local<Value>> name_argv; for (int i = 0; ; i++) { uv_dirent_t ent; @@ -596,23 +593,11 @@ void AfterScanDir(uv_fs_t* req) { if (filename.IsEmpty()) return req_wrap->Reject(error); - name_argv[name_idx++] = filename.ToLocalChecked(); - - if (name_idx >= arraysize(name_argv)) { - MaybeLocal<Value> ret = fn->Call(env->context(), names, name_idx, - name_argv); - if (ret.IsEmpty()) { - return; - } - name_idx = 0; - } - } - - if (name_idx > 0) { - fn->Call(env->context(), names, name_idx, name_argv) - .ToLocalChecked(); + name_argv.push_back(filename.ToLocalChecked()); } + Local<Array> names = + Array::New(env->isolate(), name_argv.data(), name_argv.size()); req_wrap->Resolve(names); } @@ -1497,18 +1482,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) { CHECK_GE(req_wrap_sync.req.result, 0); int r; - Local<Array> names = Array::New(isolate, 0); - Local<Function> fn = env->push_values_to_array_function(); - Local<Value> name_v[NODE_PUSH_VAL_TO_ARRAY_MAX]; - size_t name_idx = 0; - - Local<Value> types; - Local<Value> type_v[NODE_PUSH_VAL_TO_ARRAY_MAX]; - size_t type_idx; - if (with_types) { - types = Array::New(isolate, 0); - type_idx = 0; - } + std::vector<Local<Value>> name_v; + std::vector<Local<Value>> type_v; for (int i = 0; ; i++) { uv_dirent_t ent; @@ -1537,47 +1512,18 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) { return; } - name_v[name_idx++] = filename.ToLocalChecked(); - - if (name_idx >= arraysize(name_v)) { - MaybeLocal<Value> ret = fn->Call(env->context(), names, name_idx, - name_v); - if (ret.IsEmpty()) { - return; - } - name_idx = 0; - } + name_v.push_back(filename.ToLocalChecked()); if (with_types) { - type_v[type_idx++] = Integer::New(isolate, ent.type); - - if (type_idx >= arraysize(type_v)) { - MaybeLocal<Value> ret = fn->Call(env->context(), types, type_idx, - type_v); - if (ret.IsEmpty()) { - return; - } - type_idx = 0; - } + type_v.push_back(Integer::New(isolate, ent.type)); } } - if (name_idx > 0) { - MaybeLocal<Value> ret = fn->Call(env->context(), names, name_idx, name_v); - if (ret.IsEmpty()) { - return; - } - } - - if (with_types && type_idx > 0) { - MaybeLocal<Value> ret = fn->Call(env->context(), types, type_idx, type_v); - if (ret.IsEmpty()) { - return; - } - } + Local<Array> names = Array::New(isolate, name_v.data(), name_v.size()); if (with_types) { Local<Array> result = Array::New(isolate, 2); + Local<Value> types = Array::New(isolate, type_v.data(), type_v.size()); result->Set(0, names); result->Set(1, types); args.GetReturnValue().Set(result); |