diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2016-06-07 02:03:48 -0700 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2016-06-08 17:39:56 -0700 |
commit | e6f83538bd42a39867753902d31f3b370f5aa1c6 (patch) | |
tree | 78c100bc47a1dd68c97ac4bea7fc08dc9d504386 /src/choices.c | |
parent | 3b23f5714e5d4625117c52988edd972d3587db23 (diff) |
Skip sorting on empty search string
For the empty query, sorting can be the slowest part of the search.
Since the empty query gives no scores, and we've now made our sort
stable, in this case we can simply skip sorting.
A sort of 250000 entries took about ~10ms on my laptop, which is not a
huge amount. However it's not 0 and is free to skip.
Diffstat (limited to 'src/choices.c')
-rw-r--r-- | src/choices.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/choices.c b/src/choices.c index d9445c5..ab27069 100644 --- a/src/choices.c +++ b/src/choices.c @@ -151,7 +151,9 @@ void choices_search(choices_t *c, const char *search) { } } - qsort(c->results, c->available, sizeof(struct scored_result), cmpchoice); + if(*search) { + qsort(c->results, c->available, sizeof(struct scored_result), cmpchoice); + } } const char *choices_get(choices_t *c, size_t n) { |