Browse code

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.

John Hawthorn authored on 07/06/2016 09:03:48
Showing 1 changed files

... ...
@@ -151,7 +151,9 @@ void choices_search(choices_t *c, const char *search) {
151 151
 		}
152 152
 	}
153 153
 
154
-	qsort(c->results, c->available, sizeof(struct scored_result), cmpchoice);
154
+	if(*search) {
155
+		qsort(c->results, c->available, sizeof(struct scored_result), cmpchoice);
156
+	}
155 157
 }
156 158
 
157 159
 const char *choices_get(choices_t *c, size_t n) {