Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: QUnit.equiv inner refactors [Step 1] #1700

Closed
wants to merge 8 commits into from
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was meant to account for cases where length is a (custom) getter rather than a plain property or (native) array accessor. Having said that, for custom objects we shouldn't be using this function so probably fine? Just leaving here as FYI, this is not a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think this shouldnt be a problem due to a typeOf here: https://github.com/qunitjs/qunit/blob/main/src/equiv.js#L282

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;
};
}