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: Use Array#flat where supported #4459
Conversation
I've used the native
Other solution will be good (from the functional side) is to put the flatting logic into the main loop in |
Thanks for the PR! See my comment & please sign our CLA. |
To avoid massive indentation changes when migrating to ES modules.
Also, it'd be great if the PR title & commit messages followed the format from https://contribute.jquery.org/commits-and-pull-requests/#commit-guidelines We have a pre-commit hook that enforces that & it should catch those transgressions, do you have Node.js installed locally? |
Thanks, I'll check it.
Yes, I've Node.js v12.6.0 |
@aelafifi Can you make sure all usages of the |
Co-Authored-By: Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
With simplified call for the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Size increase at this point: +21 bytes. Looks fine to me, I added one comment in tests.
.flat()
function instead of .concat.apply()
I ran some benchmarks: |
I'll work on them as soon as possible, |
@aelafifi You're right that it's more universal than selector, but the main use for this historically has been to array-ify the result of selections. |
@aelafifi Sorry, my mistake, it should have been |
I'll remove the "Needs review" label for now as the PR needs some further work. |
Sorry for being late. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good. Can we get rid of the concat var file?
It still used from the flat var file as a secondary option if Array#flat isn't exists |
That’s not what I meant. We’re not using concat anywhere else so it doesn’t need to be its own var file. |
Great, it's done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment to add, otherwise looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Calling `Array.prototype.concat.apply( [], inputArray )` to flatten `inputArray` crashes for large arrays; using `Array.prototype.flat` avoids these issues in browsers that support it. In case it's necessary to support these large arrays even in older browsers, a polyfill for `Array.prototype.flat` can be loaded. This is already being done by many applications. (cherry picked from 9df4f1d) Fixes jquerygh-4320 Closes jquerygh-4459
Summary
Solve
$.map()
issue when working with large arrays on Chrome browser (#4320)Checklist