[corlib] Fixed performance regression in qsort() functions
authorJeffrey Stedfast <jeff@xamarin.com>
Tue, 7 Aug 2012 23:06:50 +0000 (19:06 -0400)
committerJeffrey Stedfast <jeff@xamarin.com>
Tue, 7 Aug 2012 23:06:50 +0000 (19:06 -0400)
commit876615e25856931250e0d3c9ef48fe7989f71fc1
tree10e48eb7f1134c99d0de81b75b76fac284bc16df
parent43955e80628074ee23dbaaee611e97e76c49483b
[corlib] Fixed performance regression in qsort() functions

Many thanks to Martin Potter who both discovered this performance
regression, providing a test case, and proposing this patch/solution.

If most of the keys have identical values as the pivot, the partitions
would become largely lopsided resulting in a worst-case scenario runtime.

We can avoid this worst-case scenario by keeping the partitions better
balanced. To do this, we can modify the "closing-in of the walls" loops
to allow items with keys identical to the pivot to be swapped to the
higher-order partition (the previous implementation would greedily
keep them in the low-order partition).

As an added bonus, this also allows us to remove the code that was needed
to keep track of the pivot index.
mcs/class/corlib/System/Array.cs