Skip to content

Commit

Permalink
refactor(yaml): use Set in inspectNode() (denoland#5778)
Browse files Browse the repository at this point in the history
  • Loading branch information
timreichen authored Aug 22, 2024
1 parent 68eb6c3 commit 1d2d33a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions yaml/_dumper_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,15 @@ function blockHeader(string: string, indentPerLevel: number): string {

function inspectNode(
object: unknown,
objects: unknown[],
objects: Set<unknown>,
duplicateObjects: Set<unknown>,
) {
if (!isObject(object)) return;
if (objects.includes(object)) {
if (objects.has(object)) {
duplicateObjects.add(object);
return;
}
objects.push(object);
objects.add(object);
const entries = Array.isArray(object) ? object : Object.values(object);
for (const value of entries) {
inspectNode(value, objects, duplicateObjects);
Expand Down Expand Up @@ -885,7 +885,7 @@ export class DumperState {
}

getDuplicateReferences(value: unknown) {
const values: unknown[] = [];
const values: Set<unknown> = new Set();
const duplicateObjects: Set<unknown> = new Set();

inspectNode(value, values, duplicateObjects);
Expand Down

0 comments on commit 1d2d33a

Please sign in to comment.