summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2014-06-29 12:56:35 -0500
committerBobby Bingham <koorogi@koorogi.info>2014-06-29 12:56:35 -0500
commit426e724002780cf36e882e664c7e340c63a2942e (patch)
tree6b3056b2d0c8362751310f2e53f5d0fad3327365
parent111c49dac18a92523c0516da006049ab8a63df3d (diff)
Don't bother merging when there are no pending elements
-rw-r--r--wikisort.c9
1 files 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) {