Change ArraySortHelper to use Comparison<T>
authorMike Danes <onemihaid@hotmail.com>
Wed, 7 Dec 2016 17:38:02 +0000 (19:38 +0200)
committerMike Danes <onemihaid@hotmail.com>
Wed, 7 Dec 2016 17:43:07 +0000 (19:43 +0200)
commitb3116a8f20d7ce04af90963cef537f0d0988b173
treefd5ff4fbb7b61c2686c3efe2796608d12476ee9f
parent0a003817d632a91fd4cc553883c6f8c937e6fd9b
Change ArraySortHelper to use Comparison<T>

The Array/List.Sort overloads that take a Comparison<T> have worse performance than the ones that take a IComparer<T>. That's because sorting is implemented around IComparer<T> and a Comparison<T> needs to be wrapped in a comparer object to be used.

At the same time, interface calls are slower than delegate calls so the existing implementation doesn't offer the best performance even when the IComparer<T> based overloads are used.

By changing the implementation to use Comparison<T> we avoid interface calls in both cases.

When IComparer<T> overloads are used a Comparison<T> delegate is created from IComparer<T>.Compare, that's an extra object allocation but sorting is faster and we avoid having two separate sorting implementations.

Commit migrated from https://github.com/dotnet/coreclr/commit/1cf86165849ffb0ab909078ef09f124f898f0461
src/coreclr/src/mscorlib/src/System/Array.cs
src/coreclr/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs
src/coreclr/src/mscorlib/src/System/Collections/Generic/List.cs
src/coreclr/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs