diff --git a/src/node_file.cc b/src/node_file.cc index 5b102269258e0b..35ca7d3514c2e5 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 error; int r; - Local names = Array::New(env->isolate(), 0); - Local fn = env->push_values_to_array_function(); - Local name_argv[NODE_PUSH_VAL_TO_ARRAY_MAX]; - size_t name_idx = 0; + std::vector> 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 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 names = + Array::New(env->isolate(), name_argv.data(), name_argv.size()); req_wrap->Resolve(names); } @@ -1497,18 +1482,8 @@ static void ReadDir(const FunctionCallbackInfo& args) { CHECK_GE(req_wrap_sync.req.result, 0); int r; - Local names = Array::New(isolate, 0); - Local fn = env->push_values_to_array_function(); - Local name_v[NODE_PUSH_VAL_TO_ARRAY_MAX]; - size_t name_idx = 0; - - Local types; - Local 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> name_v; + std::vector> type_v; for (int i = 0; ; i++) { uv_dirent_t ent; @@ -1537,47 +1512,18 @@ static void ReadDir(const FunctionCallbackInfo& args) { return; } - name_v[name_idx++] = filename.ToLocalChecked(); - - if (name_idx >= arraysize(name_v)) { - MaybeLocal 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 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 ret = fn->Call(env->context(), names, name_idx, name_v); - if (ret.IsEmpty()) { - return; - } - } - - if (with_types && type_idx > 0) { - MaybeLocal ret = fn->Call(env->context(), types, type_idx, type_v); - if (ret.IsEmpty()) { - return; - } - } + Local names = Array::New(isolate, name_v.data(), name_v.size()); if (with_types) { Local result = Array::New(isolate, 2); + Local types = Array::New(isolate, type_v.data(), type_v.size()); result->Set(0, names); result->Set(1, types); args.GetReturnValue().Set(result);