util: only sort weak entries once
This makes sure weak entries are only sorted once, while using the sorted option. PR-URL: https://github.com/nodejs/node/pull/27052 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
1940114ac3
commit
90e958aa4d
@ -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;
|
||||
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user