| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a7e73a0 commit 775ee4d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,8 @@ const bench = common.createBenchmark(main, { | |||
| 11 | 11 | method: [ | |
| 12 | 12 | 'deepEqual_Array', | |
| 13 | 13 | 'notDeepEqual_Array', | |
| 14 | + 'deepEqual_sparseArray', | ||
| 15 | + 'notDeepEqual_sparseArray', | ||
| 14 | 16 | 'deepEqual_Set', | |
| 15 | 17 | 'notDeepEqual_Set', | |
| 16 | 18 | ], | |
@@ -25,18 +27,30 @@ function run(fn, n, actual, expected) { | |||
| 25 | 27 | } | |
| 26 | 28 | ||
| 27 | 29 | function main({ n, len, method, strict }) { | |
| 28 | - const actual = []; | ||
| 29 | - const expected = []; | ||
| 30 | + let actual = Array.from({ length: len }, (_, i) => i); | ||
| 31 | + // Contain one undefined value to trigger a specific code path | ||
| 32 | + actual[0] = undefined; | ||
| 33 | + let expected = actual.slice(0); | ||
| 30 | 34 | ||
| 31 | - for (let i = 0; i < len; i++) { | ||
| 32 | - actual.push(i); | ||
| 33 | - expected.push(i); | ||
| 34 | - } | ||
| 35 | 35 | if (method.includes('not')) { | |
| 36 | 36 | expected[len - 1] += 1; | |
| 37 | 37 | } | |
| 38 | 38 | ||
| 39 | 39 | switch (method) { | |
| 40 | + case 'deepEqual_sparseArray': | ||
| 41 | + case 'notDeepEqual_sparseArray': | ||
| 42 | + actual = new Array(len); | ||
| 43 | + for (let i = 0; i < len; i += 2) { | ||
| 44 | + actual[i] = i; | ||
| 45 | + } | ||
| 46 | + expected = actual.slice(0); | ||
| 47 | + if (method.includes('not')) { | ||
| 48 | + expected[len - 2] += 1; | ||
| 49 | + run(strict ? notDeepStrictEqual : notDeepEqual, n, actual, expected); | ||
| 50 | + } else { | ||
| 51 | + run(strict ? deepStrictEqual : deepEqual, n, actual, expected); | ||
| 52 | + } | ||
| 53 | + break; | ||
| 40 | 54 | case 'deepEqual_Array': | |
| 41 | 55 | run(strict ? deepStrictEqual : deepEqual, n, actual, expected); | |
| 42 | 56 | break; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ function myersDiff(actual, expected, checkCommaDisparity = false) { | |||
| 29 | 29 | const actualLength = actual.length; | |
| 30 | 30 | const expectedLength = expected.length; | |
| 31 | 31 | const max = actualLength + expectedLength; | |
| 32 | + // TODO(BridgeAR): Cap the input in case the values go beyond the limit of 2^31 - 1. | ||
| 32 | 33 | const v = new Int32Array(2 * max + 1); | |
| 33 | 34 | const trace = []; | |
| 34 | 35 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,11 +194,9 @@ function innerDeepEqual(val1, val2, mode, memos) { | |||
| 194 | 194 | } | |
| 195 | 195 | } else { | |
| 196 | 196 | if (val1 === null || typeof val1 !== 'object') { | |
| 197 | - if (val2 === null || typeof val2 !== 'object') { | ||
| 198 | - // eslint-disable-next-line eqeqeq | ||
| 199 | - return val1 == val2 || (NumberIsNaN(val1) && NumberIsNaN(val2)); | ||
| 200 | - } | ||
| 201 | - return false; | ||
| 197 | + return (val2 === null || typeof val2 !== 'object') && | ||
| 198 | + // eslint-disable-next-line eqeqeq | ||
| 199 | + (val1 == val2 || (NumberIsNaN(val1) && NumberIsNaN(val2))); | ||
| 202 | 200 | } | |
| 203 | 201 | if (val2 === null || typeof val2 !== 'object') { | |
| 204 | 202 | return false; | |
@@ -380,9 +378,7 @@ function keyCheck(val1, val2, mode, memos, iterationType, keys2) { | |||
| 380 | 378 | } | |
| 381 | 379 | } else if (keys2.length !== ObjectKeys(val1).length) { | |
| 382 | 380 | return false; | |
| 383 | - } | ||
| 384 | - | ||
| 385 | - if (mode === kStrict) { | ||
| 381 | + } else if (mode === kStrict) { | ||
| 386 | 382 | const symbolKeysA = getOwnSymbols(val1); | |
| 387 | 383 | if (symbolKeysA.length !== 0) { | |
| 388 | 384 | let count = 0; | |
@@ -754,9 +750,9 @@ function sparseArrayEquiv(a, b, mode, memos, i) { | |||
| 754 | 750 | if (keysA.length !== keysB.length) { | |
| 755 | 751 | return false; | |
| 756 | 752 | } | |
| 757 | - for (; i < keysA.length; i++) { | ||
| 758 | - const key = keysA[i]; | ||
| 759 | - if (!hasOwn(b, key) || !innerDeepEqual(a[key], b[key], mode, memos)) { | ||
| 753 | + for (; i < keysB.length; i++) { | ||
| 754 | + const key = keysB[i]; | ||
| 755 | + if ((a[key] === undefined && !hasOwn(a, key)) || !innerDeepEqual(a[key], b[key], mode, memos)) { | ||
| 760 | 756 | return false; | |
| 761 | 757 | } | |
| 762 | 758 | } | |
@@ -778,17 +774,14 @@ function objEquiv(a, b, mode, keys2, memos, iterationType) { | |||
| 778 | 774 | return partialArrayEquiv(a, b, mode, memos); | |
| 779 | 775 | } | |
| 780 | 776 | for (let i = 0; i < a.length; i++) { | |
| 781 | - if (!innerDeepEqual(a[i], b[i], mode, memos)) { | ||
| 782 | - return false; | ||
| 783 | - } | ||
| 784 | - const isSparseA = a[i] === undefined && !hasOwn(a, i); | ||
| 785 | - const isSparseB = b[i] === undefined && !hasOwn(b, i); | ||
| 786 | - if (isSparseA !== isSparseB) { | ||
| 777 | + if (b[i] === undefined) { | ||
| 778 | + if (!hasOwn(b, i)) | ||
| 779 | + return sparseArrayEquiv(a, b, mode, memos, i); | ||
| 780 | + if (a[i] !== undefined || !hasOwn(a, i)) | ||
| 781 | + return false; | ||
| 782 | + } else if (a[i] === undefined || !innerDeepEqual(a[i], b[i], mode, memos)) { | ||
| 787 | 783 | return false; | |
| 788 | 784 | } | |
| 789 | - if (isSparseA) { | ||
| 790 | - return sparseArrayEquiv(a, b, mode, memos, i); | ||
| 791 | - } | ||
| 792 | 785 | } | |
| 793 | 786 | } else if (iterationType === kIsSet) { | |
| 794 | 787 | if (!setEquiv(a, b, mode, memos)) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments