Skip to content

Commit c2536ad

Browse files
BridgeARaddaleax
authored andcommitted
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: #60037 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jordan Harband <[email protected]>
1 parent 4136934 commit c2536ad

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/internal/util/inspect.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,11 +2281,12 @@ function formatArray(ctx, value, recurseTimes) {
22812281
const remaining = valLen - len;
22822282
const output = [];
22832283
for (let i = 0; i < len; i++) {
2284-
// Special handle sparse arrays.
2285-
if (!ObjectPrototypeHasOwnProperty(value, i)) {
2284+
const desc = ObjectGetOwnPropertyDescriptor(value, i);
2285+
if (desc === undefined) {
2286+
// Special handle sparse arrays.
22862287
return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
22872288
}
2288-
ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType));
2289+
ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType, desc));
22892290
}
22902291
if (remaining > 0) {
22912292
ArrayPrototypePush(output, remainingText(remaining));

0 commit comments

Comments
 (0)