mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
util: use Map.prototype.getOrInsert() in circular reference formatting
Signed-off-by: LiviaMedeiros <livia@cirno.name> PR-URL: https://github.com/nodejs/node/pull/67451 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
This commit is contained in:
1 parent
c8b430f17f
commit
50aa231615
1 file changed
+2
-11
@@ -1173,17 +1173,8 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
|
||||
// Using an array here is actually better for the average case than using
|
||||
// a Set. `seen` will only check for the depth and will never grow too large.
|
||||
if (ctx.seen.includes(value)) {
|
||||
let index = 1;
|
||||
if (ctx.circular === undefined) {
|
||||
ctx.circular = new SafeMap();
|
||||
ctx.circular.set(value, index);
|
||||
} else {
|
||||
index = ctx.circular.get(value);
|
||||
if (index === undefined) {
|
||||
index = ctx.circular.size + 1;
|
||||
ctx.circular.set(value, index);
|
||||
}
|
||||
}
|
||||
ctx.circular ??= new SafeMap();
|
||||
const index = ctx.circular.getOrInsert(value, ctx.circular.size + 1);
|
||||
return ctx.stylize(`[Circular *${index}]`, 'special');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user