fix(utilities): do not mutate typed arrays in shuffle() when modify is false - #9186
Open
Pcmhacker-piro wants to merge 1 commit into
Open
Pcmhacker-piro wants to merge 1 commit into
Pcmhacker-piro wants to merge 1 commit into
Conversation
Contributor
Author
|
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)