summaryrefslogtreecommitdiff
path: root/common.h
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2014-08-23 22:32:41 -0500
committerBobby Bingham <koorogi@koorogi.info>2014-08-23 22:34:18 -0500
commit59fd773ffcf6dcabe9b419f43e5324730fd603b4 (patch)
tree10025c71c78e439708dcc4fcd69a5d90b655fc9b /common.h
parenta05cbbdb939924ce04b7668225d486ae9609c2bb (diff)
Use binary search in distribute buffer
Diffstat (limited to 'common.h')
-rw-r--r--common.h7
1 files changed, 2 insertions, 5 deletions
diff --git a/common.h b/common.h
index 087ee4f..48f3d0c 100644
--- a/common.h
+++ b/common.h
@@ -47,11 +47,8 @@ static void rotate(char *base, size_t size, size_t shift)
static void distribute_buffer(char *base, size_t bufnmel, size_t sortnmel, size_t width, cmpfun cmp)
{
while (bufnmel) {
- char *sorted = base + bufnmel * width;
-
- size_t insertpos = 0;
- for (; insertpos < sortnmel && cmp(base, sorted + insertpos * width) > 0; insertpos++);
-
+ char *sorted = base + bufnmel * width;
+ size_t insertpos = binary_search(base, sorted, sortnmel, width, cmp);
if (insertpos > 0) {
rotate(base, (bufnmel + insertpos) * width, bufnmel * width);
}