Skip to content

Commit

Permalink
util: only sort weak entries once
Browse files Browse the repository at this point in the history
This makes sure weak entries are only sorted once, while using the
sorted option.

PR-URL: #27052
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR committed Apr 15, 2019
1 parent 1940114 commit 90e958a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,9 +1200,10 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
output[i] = formatValue(ctx, entries[i], recurseTimes);
}
ctx.indentationLvl -= 2;
if (state === kWeak) {
if (state === kWeak && !ctx.sorted) {
// Sort all entries to have a halfway reliable output (if more entries than
// retrieved ones exist, we can not reliably return the same output).
// retrieved ones exist, we can not reliably return the same output) if the
// output is not sorted anyway.
output = output.sort();
}
const remaining = entries.length - maxLength;
Expand All @@ -1227,9 +1228,11 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
output[i] = `${formatValue(ctx, entries[pos], recurseTimes)}` +
` => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
}
// Sort all entries to have a halfway reliable output (if more entries
// than retrieved ones exist, we can not reliably return the same output).
output = output.sort();
// Sort all entries to have a halfway reliable output (if more entries than
// retrieved ones exist, we can not reliably return the same output) if the
// output is not sorted anyway.
if (!ctx.sorted)
output = output.sort();
} else {
for (; i < maxLength; i++) {
const pos = i * 2;
Expand Down

0 comments on commit 90e958a

Please sign in to comment.