Archie's mod to qsort: | >- if (swap_cnt == 0) { /* Switch to insertion sort */ | >+ if (n <= 32 && swap_cnt == 0) { /* Switch to insertion sort */
As Akira Wada points out, this eliminates the benefit of the optimization in the first place, which is to let isort take over if the data is largely sorted in the first place. Akira Wada's alternative mod: | + pl = (char *)a; pn = (char *)a + (n - 1) * es; | + while (pl < pn && cmp(pl, pl + es) <= 0) pl += es; | + if (pl >= pn) return; This is a little more comprehensive, but does throw in an extra pass of comparisons, which (I'm sure) someone would complain about. The alteration that I've tried and tested is to have the isort bail back to qsort if it does more than N swaps. I put N at 1024, which worked for my data :). This is almost guaranteed to do no more work than the current logic, because it it only gives up on the isort when it has evidence that the isort is doing too much work. Christopher To Unsubscribe: send mail to majord...@freebsd.org with "unsubscribe freebsd-hackers" in the body of the message