Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use MemoryExtensions.Sort where available.
  • Loading branch information
grbell-ms committed Jun 17, 2022
commit 26a6c0dcdd5a7c0eacc6a98a5ad28bf080410285
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<IsPackable>true</IsPackable>
Expand Down Expand Up @@ -109,6 +109,7 @@ System.Collections.Immutable.ImmutableStack&lt;T&gt;</PackageDescription>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<Reference Include="System.Collections" />
<Reference Include="System.Linq" />
<Reference Include="System.Memory" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,11 +933,17 @@ public void Sort(Comparison<T> comparison)

if (Count > 1)
{
#if NET6_0_OR_GREATER
// MemoryExtensions.Sort is not available in .NET Framework / Standard 2.0.
// But the overload with a Comparison argumrnt doesn't allocate.
_elements.AsSpan(0, _count).Sort(comparison);
#else
// Array.Sort does not have an overload that takes both bounds and a Comparison.
// We could special case _count == _elements.Length in order to try to avoid
// the IComparer allocation, but the Array.Sort overload that takes a Comparison
// allocates such an IComparer internally, anyway.
Array.Sort(_elements, 0, _count, Comparer<T>.Create(comparison));
#endif
}
}

Expand Down