| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -349,10 +349,6 @@ function setEquiv(a, b, strict, memo) { | |||
| 349 | 349 | // This is a lazily initiated Set of entries which have to be compared | |
| 350 | 350 | // pairwise. | |
| 351 | 351 | var set = null; | |
| 352 | - // When the sets contain only value types (eg, lots of numbers), and we're in | ||
| 353 | - // strict mode or if all entries strictly match, we don't need to match the | ||
| 354 | - // entries in a pairwise way. In that case this initialization is done lazily | ||
| 355 | - // to avoid the allocation & bookkeeping cost. | ||
| 356 | 352 | for (const val of a) { | |
| 357 | 353 | // Note: Checking for the objects first improves the performance for object | |
| 358 | 354 | // heavy sets but it is a minor slow down for primitives. As they are fast | |
@@ -373,7 +369,7 @@ function setEquiv(a, b, strict, memo) { | |||
| 373 | 369 | ||
| 374 | 370 | if (set !== null) { | |
| 375 | 371 | for (const val of b) { | |
| 376 | - // In non-strict-mode we have to check if a primitive value is already | ||
| 372 | + // We have to check if a primitive value is already | ||
| 377 | 373 | // matching and only if it's not, go hunting for it. | |
| 378 | 374 | if (typeof val === 'object' && val !== null) { | |
| 379 | 375 | if (!setHasEqualElement(set, val, strict, memo)) | |
@@ -449,10 +445,13 @@ function mapHasLoosePrim(a, b, key1, memo, item1, item2) { | |||
| 449 | 445 | return false; | |
| 450 | 446 | ||
| 451 | 447 | for (const val of setA) { | |
| 452 | - if (!setHasEqualElement(setB, val, false, memo)) | ||
| 448 | + if (typeof val === 'object' && val !== null) { | ||
| 449 | + if (!setHasEqualElement(setB, val, false, memo)) | ||
| 450 | + return false; | ||
| 451 | + } else if (!setB.has(val) && !setHasLoosePrim(setA, setB, val)) { | ||
| 453 | 452 | return false; | |
| 453 | + } | ||
| 454 | 454 | } | |
| 455 | - | ||
| 456 | 455 | return true; | |
| 457 | 456 | } | |
| 458 | 457 | ||
@@ -472,34 +471,26 @@ function mapHasEqualEntry(set, map, key1, item1, strict, memo) { | |||
| 472 | 471 | } | |
| 473 | 472 | ||
| 474 | 473 | function mapEquiv(a, b, strict, memo) { | |
| 475 | - // Caveat: In non-strict mode, this implementation does not handle cases | ||
| 476 | - // where maps contain two equivalent-but-not-reference-equal keys. | ||
| 477 | 474 | if (a.size !== b.size) | |
| 478 | 475 | return false; | |
| 479 | 476 | ||
| 480 | 477 | var set = null; | |
| 481 | 478 | ||
| 482 | 479 | for (const [key, item1] of a) { | |
| 483 | - // By directly retrieving the value we prevent another b.has(key) check in | ||
| 484 | - // almost all possible cases. | ||
| 485 | - const item2 = b.get(key); | ||
| 486 | - if (item2 === undefined) { | ||
| 487 | - // Just like setEquiv above but in addition we have to make sure the | ||
| 488 | - // values are also equal. | ||
| 489 | - if (typeof key === 'object' && key !== null) { | ||
| 490 | - if (set === null) { | ||
| 491 | - set = new Set(); | ||
| 492 | - } | ||
| 493 | - set.add(key); | ||
| 494 | - // Note: we do not have to pass memo in this case as at least one item | ||
| 495 | - // is undefined. | ||
| 496 | - } else if ((!innerDeepEqual(item1, item2, strict) || !b.has(key)) && | ||
| 497 | - (strict || !mapHasLoosePrim(a, b, key, memo, item1))) { | ||
| 480 | + if (typeof key === 'object' && key !== null) { | ||
| 481 | + if (set === null) { | ||
| 482 | + set = new Set(); | ||
| 483 | + } | ||
| 484 | + set.add(key); | ||
| 485 | + } else { | ||
| 486 | + // By directly retrieving the value we prevent another b.has(key) check in | ||
| 487 | + // almost all possible cases. | ||
| 488 | + const item2 = b.get(key); | ||
| 489 | + if ((item2 === undefined && !b.has(key) || | ||
| 490 | + !innerDeepEqual(item1, item2, strict, memo)) && | ||
| 491 | + (strict || !mapHasLoosePrim(a, b, key, memo, item1, item2))) { | ||
| 498 | 492 | return false; | |
| 499 | 493 | } | |
| 500 | - } else if (!innerDeepEqual(item1, item2, strict, memo) && | ||
| 501 | - (strict || !mapHasLoosePrim(a, b, key, memo, item1, item2))) { | ||
| 502 | - return false; | ||
| 503 | 494 | } | |
| 504 | 495 | } | |
| 505 | 496 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments