Skip to content

Commit cf2cb4d

Browse files
committed
perf(logger): improved performance of circular removal
1 parent 2e6bc64 commit cf2cb4d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/logger/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ function removeCircular(obj: any, refs: any[] = []): any {
6161
return obj.toJSON();
6262
}
6363
// Only check for circularity among ancestors in the recursion stack.
64-
if (refs.indexOf(obj) !== -1) {
64+
if (refs.includes(obj)) {
6565
return "[Circular]";
6666
}
6767
// Add the current object to the recursion stack.
6868
refs.push(obj);
6969

7070
const returnObj: any = Array.isArray(obj) ? [] : {};
7171
for (const key in obj) {
72-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
73-
returnObj[key] = removeCircular(obj[key], refs);
74-
}
72+
returnObj[key] = removeCircular(obj[key], refs);
7573
}
74+
7675
// Remove the current object from the stack once its properties are processed.
7776
refs.pop();
7877
return returnObj;

0 commit comments

Comments
 (0)