fix(utilities): do not mutate typed arrays in shuffle() when modify is false - #9186
Conversation
|
Hi @davepagurek @ksen0! 👋 Could you please take a look at this PR when you get a chance? It resolves #9128 by removing the legacy
Thank you so much! |
|
Hey @perminder-17, sir My real GitHub contribution account is Pcmhacker-piro. But the git bot wrongly added my other account, Pcmhacker-hero, to the contribution list, so please update this, and future commits will be added via Pcmhacker-piro. Thanks, sir. |
|
@all-contributors please add @Pcmhacker-piro for code |
|
@Pcmhacker-piro already contributed before to code |
|
@perminder-17
|
|
Hi, I think we misread your message as being related to the all-contributors bot which does have your @ksen0 now that this is merged, we would have to rebase our branches and rewrite history to change the author of commits. |
|
Thanks for checking. Yes, the issue I’m referring to is specifically the repository’s Contributors list. My commits are currently being attributed to my old GitHub account there, while I want them to be attributed to my current -piro account. I understand that this is related to the email address used in the commits. Since the PR is already merged, is there any way to correct the contributor attribution without rewriting the repository history? If not, I’ll make sure my Git email is correctly configured for future contributions. |
|
Unfortunately generally we want to avoid force pushes to |

Resolves #9128
Changes:
shuffle()documentation states: "By default, the original array won't be modified. Instead, a copy will be created, shuffled, and returned."However, in
src/utilities/utility_functions.js,shuffle()contained a legacyisViewcheck:Because
isViewwas truthy for anyTypedArray(Float32Array,Uint8Array, etc.), typed arrays were always treated as ifmodifywastrue, causing them to be mutated in-place and returning the original array reference (b === a) even whenmodifywas omitted orfalse.TypedArray.prototype.slice()has been standard across all modern JavaScript runtimes since ES2015, returning a copy of the typed array.This PR:
isViewcondition insrc/utilities/utility_functions.jsso thatarr = modify ? arr : arr.slice();.modifyis false (default),arr.slice()creates a copy for typed arrays as well as regular arrays without modifying the input array.modifyis true, the array is still modified in-place as expected.test/unit/utilities/utility_functions.jscovering both default (non-mutating) and in-place (modify: true) behavior for both regular arrays and typed arrays.Verification:
1. Terminal Output & Verification
PR Checklist
npm run lintpasses (0 errors)