Closed Bug 1784090 Opened 2 years ago Closed 2 years ago

Create fewer copies in TypedArrayToSorted and ArrayToSorted

Categories

(Core :: JavaScript: Standard Library, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
105 Branch
Tracking Status
firefox105 --- fixed

People

(Reporter: anba, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(5 files)

TypedArrayToSorted calls TypedArraySort, which in turn calls MergeSortTypedArray. MergeSortTypedArray creates another copy of the TypedArray, which isn't actually necessary for TypedArrayToSorted. The same issue applies for ArrayToSorted.

Change MergeSortTypedArray to return the sorted array. TypedArraySort now
needs to copy the sorted elements back into the original array and
TypedArrayToSorted can directly return the sorted array. When TypedArrayToSorted
is called without a comparator function, we still have to create a copy in
TypedArrayToSorted which is then passed to TypedArrayNativeSort. When the
input has fewer than two elements, we only have to copy the input without performing
any sort operations.

We generally prefer single-line comments in new code.

Depends on D154262

Inline ArraySort into ArrayToSorted in preparation for the next part.

Depends on D154263

Change MergeSort to directly modify its input instead of creating a copy.
ArraySort now needs to copy the input and re-arrange any holes, whereas
ArrayToSorted can directly return the result from MergeSort.

Depends on D154264

Pushed by andre.bargull@gmail.com: https://hg.mozilla.org/integration/autoland/rev/9c38d51940e8 Part 1: Create fewer copies in TypedArrayToSorted. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/ac8bb0be9f26 Part 2: Remove SortArray with direct call to ArraySort. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/3492785e6bb1 Part 3: Change comments to single-line comments. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/3966a0f0f413 Part 4: Inline ArraySort into ArrayToSorted. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/35d068070f81 Part 5: Avoid copying the array for ArrayToSorted. r=mgaudet
Pushed by andre.bargull@gmail.com: https://hg.mozilla.org/integration/autoland/rev/aef2c47ad1c4 Part 1: Create fewer copies in TypedArrayToSorted. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/8ea5622a4264 Part 2: Remove SortArray with direct call to ArraySort. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/61db7e2983a3 Part 3: Change comments to single-line comments. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/f98b7c864bea Part 4: Inline ArraySort into ArrayToSorted. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/98f1a8e535e9 Part 5: Avoid copying the array for ArrayToSorted. r=mgaudet
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: