Skip to content

Commit

Permalink
Core: refactor equiv for easier readability
Browse files Browse the repository at this point in the history
Small removals/adjustments to make the code more readable.
  • Loading branch information
izelnakri committed Aug 16, 2022
1 parent 5e367cb commit 5e5ce7d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/equiv.js
Expand Up @@ -66,13 +66,11 @@ function breadthFirstCompareChild (a, b) {
// over the pair.
if (a === b) {
return true;
}
if (!isContainer(a)) {
} else if (!isContainer(a)) {
return typeEquiv(a, b);
}
if (pairs.every((pair) => pair.a !== a || pair.b !== b)) {
} else if (pairs.every((pair) => pair.a !== a || pair.b !== b)) {
// Not yet started comparing this pair
pairs.push({ a: a, b: b });
pairs.push({ a, b });
}
return true;
}
Expand Down Expand Up @@ -103,13 +101,12 @@ const callbacks = {
},

array (a, b) {
const len = a.length;
if (len !== b.length) {
if (a.length !== b.length) {
// Safe and faster
return false;
}

for (let i = 0; i < len; i++) {
for (let i = 0; i < a.length; i++) {
// Compare non-containers; queue non-reference-equal containers
if (!breadthFirstCompareChild(a[i], b[i])) {
return false;
Expand Down Expand Up @@ -284,7 +281,7 @@ function innerEquiv (a, b) {
}

// Clear the global pair queue and add the top-level values being compared
pairs = [{ a: a, b: b }];
pairs = [{ a, b }];

for (let i = 0; i < pairs.length; i++) {
const pair = pairs[i];
Expand All @@ -311,4 +308,4 @@ export default function equiv (...args) {
// Release any retained objects
pairs.length = 0;
return result;
};
}

0 comments on commit 5e5ce7d

Please sign in to comment.