Skip to content

Commit df72dc9

Browse files
BridgeARaduh95
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 26394cd commit df72dc9

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
@@ -2022,11 +2022,12 @@ function formatArray(ctx, value, recurseTimes) {
20222022
const remaining = valLen - len;
20232023
const output = [];
20242024
for (let i = 0; i < len; i++) {
2025-
// Special handle sparse arrays.
2026-
if (!ObjectPrototypeHasOwnProperty(value, i)) {
2025+
const desc = ObjectGetOwnPropertyDescriptor(value, i);
2026+
if (desc === undefined) {
2027+
// Special handle sparse arrays.
20272028
return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
20282029
}
2029-
ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType));
2030+
ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType, desc));
20302031
}
20312032
if (remaining > 0) {
20322033
ArrayPrototypePush(output, remainingText(remaining));

0 commit comments

Comments
 (0)