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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Equality check between two sparse arrays iterate over holes to compare them #11055
Comments
@SimenB If I'm not wrong I think the only remaining part for this issue was the fact that the computation of the stringified version of an Indeed Jest creates something like Not sure 100% but if I'm not wrong the stringified version is computed even if the assertion passes. But I'm really not sure about that last statement. |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
馃悰 Bug Report
Checking the equality of two sparse arrays seems to iterate over all the cells of each of those (as soon as they have the same size).
By looking at the code I found that there was a special case for sparse arrays: https://github.com/facebook/jest/blob/0a9e77d5e75adc87f8d7497ec30472c661c6fc11/packages/expect/src/utils.ts#L334
But its seems that the special case only checks hole versus undefined case as it finally calls equals that will iterate over all indexes one after the other: https://github.com/facebook/jest/blob/0a9e77d5e75adc87f8d7497ec30472c661c6fc11/packages/expect/src/jasmineUtils.ts#L153
I am wondering if we could not have it faster. Actually for sparse arrays iterating over the keys and not all the indexes should be enough to confirm equality, no?
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Ends quickly: lengths are equal, keys are equal, values associated to keys are equal.
envinfo
Context
I am currently working into adding generators for sparse arrays in fast-check (see dubzzz/fast-check#1447). My plan was to provide such helper built-in as I believed it could help to detect some bugs...
The text was updated successfully, but these errors were encountered: