Patch: Improve std::sort performance (particularly on reverse-ordered lists)

Marc Glisse marc.glisse@inria.fr
Wed Sep 25 13:03:00 GMT 2013


On Wed, 25 Sep 2013, Christopher Jefferson wrote:

> There are a selection of ways of fixing this. This patch switches the
> median calculation from considering then first, mid, last locations to
> on first+1, mid, last-1 (there is no reason in this bug to consider
> last-1 instead of last, but I thought it wouldn't do any harm, and
> might avoid other issues of accidentally choosing a bad pivot.

It's going to conflict with Francois' patch, don't know which one of you 
will be first ;-)

I think the median function could be slightly shorter (but slower?) with 
something like:

if(*a<*b) std::swap(a,b);
proceed as if we were in the else branch.

-- 
Marc Glisse



More information about the Libstdc++ mailing list