Skip to content

Commit 90e958a

Browse files
committed
util: only sort weak entries once
This makes sure weak entries are only sorted once, while using the sorted option. PR-URL: #27052 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1940114 commit 90e958a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/internal/util/inspect.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -1200,9 +1200,10 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
12001200
output[i] = formatValue(ctx, entries[i], recurseTimes);
12011201
}
12021202
ctx.indentationLvl -= 2;
1203-
if (state === kWeak) {
1203+
if (state === kWeak && !ctx.sorted) {
12041204
// Sort all entries to have a halfway reliable output (if more entries than
1205-
// retrieved ones exist, we can not reliably return the same output).
1205+
// retrieved ones exist, we can not reliably return the same output) if the
1206+
// output is not sorted anyway.
12061207
output = output.sort();
12071208
}
12081209
const remaining = entries.length - maxLength;
@@ -1227,9 +1228,11 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
12271228
output[i] = `${formatValue(ctx, entries[pos], recurseTimes)}` +
12281229
` => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
12291230
}
1230-
// Sort all entries to have a halfway reliable output (if more entries
1231-
// than retrieved ones exist, we can not reliably return the same output).
1232-
output = output.sort();
1231+
// Sort all entries to have a halfway reliable output (if more entries than
1232+
// retrieved ones exist, we can not reliably return the same output) if the
1233+
// output is not sorted anyway.
1234+
if (!ctx.sorted)
1235+
output = output.sort();
12331236
} else {
12341237
for (; i < maxLength; i++) {
12351238
const pos = i * 2;

0 commit comments

Comments
 (0)