From: Ian Lance Taylor Date: Fri, 7 Mar 2014 15:52:48 +0000 (+0000) Subject: * sort.c (backtrace_qsort): Use middle element as pivot. X-Git-Tag: releases/gcc-4.9.0~541 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbe2084238e45a60aa6e6b0469bd9e0c4ef15b2f;p=thirdparty%2Fgcc.git * sort.c (backtrace_qsort): Use middle element as pivot. From-SVN: r208403 --- diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index abbea3ed6e8b..8a1a8e74a323 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,7 @@ +2014-03-07 Ian Lance Taylor + + * sort.c (backtrace_qsort): Use middle element as pivot. + 2014-03-06 Ian Lance Taylor * sort.c: New file. diff --git a/libbacktrace/sort.c b/libbacktrace/sort.c index 88f923142247..8c4760f8aa31 100644 --- a/libbacktrace/sort.c +++ b/libbacktrace/sort.c @@ -69,6 +69,12 @@ backtrace_qsort (void *basearg, size_t count, size_t size, if (count < 2) return; + /* The symbol table and DWARF tables, which is all we use this + routine for, tend to be roughly sorted. Pick the middle element + in the array as our pivot point, so that we are more likely to + cut the array in half for each recursion step. */ + swap (base, base + (count / 2) * size, size); + mid = 0; for (i = 1; i < count; i++) {