console,util: improve array inspection performance

There is no need to do the own property check, since the descriptor
is needed right afterwards anyway.

PR-URL: https://github.com/nodejs/node/pull/60037
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
Ruben Bridgewater 2025-09-27 21:57:35 +02:00 committed by Anna Henningsen
parent 413693481f
commit c2536adc28
No known key found for this signature in database

View File

@ -2281,11 +2281,12 @@ function formatArray(ctx, value, recurseTimes) {
const remaining = valLen - len;
const output = [];
for (let i = 0; i < len; i++) {
// Special handle sparse arrays.
if (!ObjectPrototypeHasOwnProperty(value, i)) {
const desc = ObjectGetOwnPropertyDescriptor(value, i);
if (desc === undefined) {
// Special handle sparse arrays.
return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
}
ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType));
ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType, desc));
}
if (remaining > 0) {
ArrayPrototypePush(output, remainingText(remaining));