fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 827ebd97b56b55b2a1e6824e257a6badc3b438a6 parent 20a41f4065401a29fd5448754260e753ccfe0068 Author: John Hawthorn <john.hawthorn@gmail.com> Date: Sun, 24 Apr 2016 13:37:36 -0700 Set sensible initial sizes for growing arrays Any values should work here, and it doesn't seem to make a siginificant difference to startup time, as this only adds or reduces a few realloc calls. Starts input buffer at 4k of memory, which is nice for being the size of a page and the size usually used in the read syscall. Initial choice capacity set to 128, by assuming that candidates average 32 characters long. Diffstat:
| M | choices.c | | | 10 | +++++++--- |
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/choices.c b/choices.c @@ -5,7 +5,11 @@ #include "choices.h" #include "match.h" -#define INITIAL_CAPACITY 1 +/* Initial size of buffer for storing input in memory */ +#define INITIAL_BUFFER_SIZE 4096 + +/* Initial size of choices array */ +#define INITIAL_CHOICE_CAPACITY 128 static int cmpchoice(const void *_idx1, const void *_idx2) { const struct scored_result *a = _idx1; @@ -30,7 +34,7 @@ static void *safe_realloc(void *buffer, size_t size) { } void choices_fread(choices_t *c, FILE *file) { - size_t bufsize = 65536, pos = 0; + size_t bufsize = INITIAL_BUFFER_SIZE, pos = 0; char *buf = safe_realloc(NULL, bufsize); /* Continue reading until we get a "short" read, indicating EOF */ @@ -76,7 +80,7 @@ void choices_init(choices_t *c) { c->results = NULL; c->capacity = c->size = 0; choices_reset_search(c); - choices_resize(c, INITIAL_CAPACITY); + choices_resize(c, INITIAL_CHOICE_CAPACITY); } void choices_free(choices_t *c) {