@@ -1608,27 +1608,21 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
16081608 Local<Array> ary = Array::New (args.GetIsolate ());
16091609 Local<Context> ctx = env->context ();
16101610 Local<Function> fn = env->push_values_to_array_function ();
1611- static const size_t argc = 8 ;
1612- Local<Value> argv[argc];
1613- size_t i = 0 ;
1611+ Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1612+ size_t idx = 0 ;
16141613
16151614 for (auto w : *env->req_wrap_queue ()) {
1616- if (w->persistent ().IsEmpty () == false ) {
1617- argv[i++ % argc] = w->object ();
1618- if ((i % argc) == 0 ) {
1619- HandleScope scope (env->isolate ());
1620- fn->Call (ctx, ary, argc, argv).ToLocalChecked ();
1621- for (auto && arg : argv) {
1622- arg = Local<Value>();
1623- }
1624- }
1615+ if (w->persistent ().IsEmpty ())
1616+ continue ;
1617+ argv[idx] = w->object ();
1618+ if (++idx >= ARRAY_SIZE (argv)) {
1619+ fn->Call (ctx, ary, idx, argv).ToLocalChecked ();
1620+ idx = 0 ;
16251621 }
16261622 }
16271623
1628- const size_t remainder = i % argc;
1629- if (remainder > 0 ) {
1630- HandleScope scope (env->isolate ());
1631- fn->Call (ctx, ary, remainder, argv).ToLocalChecked ();
1624+ if (idx > 0 ) {
1625+ fn->Call (ctx, ary, idx, argv).ToLocalChecked ();
16321626 }
16331627
16341628 args.GetReturnValue ().Set (ary);
@@ -1641,7 +1635,10 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
16411635 Environment* env = Environment::GetCurrent (args);
16421636
16431637 Local<Array> ary = Array::New (env->isolate ());
1644- int i = 0 ;
1638+ Local<Context> ctx = env->context ();
1639+ Local<Function> fn = env->push_values_to_array_function ();
1640+ Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1641+ size_t idx = 0 ;
16451642
16461643 Local<String> owner_sym = env->owner_string ();
16471644
@@ -1652,7 +1649,14 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
16521649 Local<Value> owner = object->Get (owner_sym);
16531650 if (owner->IsUndefined ())
16541651 owner = object;
1655- ary->Set (i++, owner);
1652+ argv[idx] = owner;
1653+ if (++idx >= ARRAY_SIZE (argv)) {
1654+ fn->Call (ctx, ary, idx, argv).ToLocalChecked ();
1655+ idx = 0 ;
1656+ }
1657+ }
1658+ if (idx > 0 ) {
1659+ fn->Call (ctx, ary, idx, argv).ToLocalChecked ();
16561660 }
16571661
16581662 args.GetReturnValue ().Set (ary);
0 commit comments