@@ -360,10 +360,6 @@ function setEquiv(a, b, strict, memo) {
360
360
// This is a lazily initiated Set of entries which have to be compared
361
361
// pairwise.
362
362
var set = null ;
363
- // When the sets contain only value types (eg, lots of numbers), and we're in
364
- // strict mode or if all entries strictly match, we don't need to match the
365
- // entries in a pairwise way. In that case this initialization is done lazily
366
- // to avoid the allocation & bookkeeping cost.
367
363
for ( const val of a ) {
368
364
// Note: Checking for the objects first improves the performance for object
369
365
// heavy sets but it is a minor slow down for primitives. As they are fast
@@ -384,7 +380,7 @@ function setEquiv(a, b, strict, memo) {
384
380
385
381
if ( set !== null ) {
386
382
for ( const val of b ) {
387
- // In non-strict-mode we have to check if a primitive value is already
383
+ // We have to check if a primitive value is already
388
384
// matching and only if it's not, go hunting for it.
389
385
if ( typeof val === 'object' && val !== null ) {
390
386
if ( ! setHasEqualElement ( set , val , strict , memo ) )
@@ -460,10 +456,13 @@ function mapHasLoosePrim(a, b, key1, memo, item1, item2) {
460
456
return false ;
461
457
462
458
for ( const val of setA ) {
463
- if ( ! setHasEqualElement ( setB , val , false , memo ) )
459
+ if ( typeof val === 'object' && val !== null ) {
460
+ if ( ! setHasEqualElement ( setB , val , false , memo ) )
461
+ return false ;
462
+ } else if ( ! setB . has ( val ) && ! setHasLoosePrim ( setA , setB , val ) ) {
464
463
return false ;
464
+ }
465
465
}
466
-
467
466
return true ;
468
467
}
469
468
@@ -483,34 +482,26 @@ function mapHasEqualEntry(set, map, key1, item1, strict, memo) {
483
482
}
484
483
485
484
function mapEquiv ( a , b , strict , memo ) {
486
- // Caveat: In non-strict mode, this implementation does not handle cases
487
- // where maps contain two equivalent-but-not-reference-equal keys.
488
485
if ( a . size !== b . size )
489
486
return false ;
490
487
491
488
var set = null ;
492
489
493
490
for ( const [ key , item1 ] of a ) {
494
- // By directly retrieving the value we prevent another b.has(key) check in
495
- // almost all possible cases.
496
- const item2 = b . get ( key ) ;
497
- if ( item2 === undefined ) {
498
- // Just like setEquiv above but in addition we have to make sure the
499
- // values are also equal.
500
- if ( typeof key === 'object' && key !== null ) {
501
- if ( set === null ) {
502
- set = new Set ( ) ;
503
- }
504
- set . add ( key ) ;
505
- // Note: we do not have to pass memo in this case as at least one item
506
- // is undefined.
507
- } else if ( ( ! innerDeepEqual ( item1 , item2 , strict ) || ! b . has ( key ) ) &&
508
- ( strict || ! mapHasLoosePrim ( a , b , key , memo , item1 ) ) ) {
491
+ if ( typeof key === 'object' && key !== null ) {
492
+ if ( set === null ) {
493
+ set = new Set ( ) ;
494
+ }
495
+ set . add ( key ) ;
496
+ } else {
497
+ // By directly retrieving the value we prevent another b.has(key) check in
498
+ // almost all possible cases.
499
+ const item2 = b . get ( key ) ;
500
+ if ( ( item2 === undefined && ! b . has ( key ) ||
501
+ ! innerDeepEqual ( item1 , item2 , strict , memo ) ) &&
502
+ ( strict || ! mapHasLoosePrim ( a , b , key , memo , item1 , item2 ) ) ) {
509
503
return false ;
510
504
}
511
- } else if ( ! innerDeepEqual ( item1 , item2 , strict , memo ) &&
512
- ( strict || ! mapHasLoosePrim ( a , b , key , memo , item1 , item2 ) ) ) {
513
- return false ;
514
505
}
515
506
}
516
507
0 commit comments