From 426e724002780cf36e882e664c7e340c63a2942e Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sun, 29 Jun 2014 12:56:35 -0500 Subject: Don't bother merging when there are no pending elements --- wikisort.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wikisort.c b/wikisort.c index b2de063..4d69582 100644 --- a/wikisort.c +++ b/wikisort.c @@ -204,15 +204,18 @@ void wikisort(void *unsorted, size_t nmel, size_t width, cmpfun cmp) /* merge any previous pending as and bs */ nmel_pend_b -= offset; - if (nmel_pend_a) { + if (nmel_pend_a && nmel_pend_b) { merge_blocks(base, penda, nmel_pend_a, nmel_pend_b, width, cmp); } + + nmel_pend_a = bnmel; + nmel_pend_b = offset; } else { + nmel_pend_a = 0; + nmel_pend_b = 0; offset = 0; } - nmel_pend_a = bnmel; - nmel_pend_b = offset; penda = a.base - offset * width; a.base += bwidth; if (--a.blocks) { -- cgit v1.2.3