@@ -49,7 +49,11 @@ const deepEqualJsonLikeInner = (
4949 maxDepth : number ,
5050 priorityKeys : readonly string [ ] ,
5151 priorityKeySet : ReadonlySet < string > ,
52- context : { hitMaxDepth : boolean ; maxDepthHitDepth : number | null }
52+ context : {
53+ hitMaxDepth : boolean ;
54+ maxDepthHitDepth : number | null ;
55+ objectKeySetsByDepth : Array < Set < string > | undefined > ;
56+ }
5357) : boolean => {
5458 if ( depth > maxDepth ) {
5559 context . hitMaxDepth = true ;
@@ -110,7 +114,17 @@ const deepEqualJsonLikeInner = (
110114 . filter ( ( key ) => ! priorityKeySet . has ( key ) ) ;
111115 if ( aKeys . length !== bKeys . length ) return false ;
112116
113- const bKeySet = new Set ( bKeys ) ;
117+ const existingKeySet = context . objectKeySetsByDepth [ depth ] ;
118+ const bKeySet = existingKeySet ?? new Set < string > ( ) ;
119+ if ( existingKeySet ) {
120+ bKeySet . clear ( ) ;
121+ } else {
122+ context . objectKeySetsByDepth [ depth ] = bKeySet ;
123+ }
124+
125+ for ( const key of bKeys ) {
126+ bKeySet . add ( key ) ;
127+ }
114128 for ( const key of aKeys ) {
115129 if ( ! bKeySet . has ( key ) ) return false ;
116130 if (
@@ -149,7 +163,7 @@ export const deepEqualJsonLike = (
149163 const nowMs = options . nowMs ?? defaultNowMs ;
150164 const logger = options . logger ;
151165
152- const context = { hitMaxDepth : false , maxDepthHitDepth : null as number | null } ;
166+ const context = { hitMaxDepth : false , maxDepthHitDepth : null , objectKeySetsByDepth : [ ] } ;
153167 const start = nowMs ( ) ;
154168 const result = deepEqualJsonLikeInner (
155169 a ,
0 commit comments