Remove allocation in ImmutableArray Builder Sort (#70850)
authorGregory Bell <65985703+grbell-ms@users.noreply.github.com>
Tue, 21 Jun 2022 02:27:34 +0000 (19:27 -0700)
committerGitHub <noreply@github.com>
Tue, 21 Jun 2022 02:27:34 +0000 (05:27 +0300)
commit30bf66a0ef5342ea229a52e2d5b377f3102948a4
tree6836a5bb4ada7e2aef6c3a40d5c310e597f81aea
parent87194f2f524704f1bf424a807ac2d258d0055d50
Remove allocation in ImmutableArray Builder Sort (#70850)

* Remove allocation in ImmutableArray Builder Sort

`ImmutableArray<T>.Builder.Sort(Comparison<T> comparison)` allocates a new instance of `Comparer<T>` using `comparison`. Then `ArraySort` allocates a new delegate from `comparer.Compare`. Both allocations can be eliminated by calling `Array.Sort<T>(T[] array, Comparison<T> comparison)` directly.

* Sort only valid range of array

* Use MemoryExtensions.Sort where available.

* Update src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Builder.cs

Fix spelling mistake.

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
src/libraries/System.Collections.Immutable/src/System.Collections.Immutable.csproj
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Builder.cs