Skip to content

Commit 0bf022d

Browse files
BridgeARtargos
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 <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>
1 parent d949222 commit 0bf022d

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
@@ -2029,11 +2029,12 @@ function formatArray(ctx, value, recurseTimes) {
20292029
const remaining = valLen - len;
20302030
const output = [];
20312031
for (let i = 0; i < len; i++) {
2032-
// Special handle sparse arrays.
2033-
if (!ObjectPrototypeHasOwnProperty(value, i)) {
2032+
const desc = ObjectGetOwnPropertyDescriptor(value, i);
2033+
if (desc === undefined) {
2034+
// Special handle sparse arrays.
20342035
return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
20352036
}
2036-
ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType));
2037+
ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType, desc));
20372038
}
20382039
if (remaining > 0) {
20392040
ArrayPrototypePush(output, remainingText(remaining));

0 commit comments

Comments
 (0)