fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 0788d9bae552fe42da1da87f401cc94722c62f43 parent a3a1186e7c7f53a40acdbfceebca9bc8975aa335 Author: John Hawthorn <john.hawthorn@gmail.com> Date: Wed, 22 Jun 2016 21:26:21 -0700 Store worker_count on choices_t Diffstat:
| M | src/choices.c | | | 14 | +++++++------- |
| M | src/choices.h | | | 2 | ++ |
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/choices.c b/src/choices.c @@ -104,6 +104,8 @@ void choices_init(choices_t *c) { c->capacity = c->size = 0; choices_resize(c, INITIAL_CHOICE_CAPACITY); + c->worker_count = 8; + choices_reset_search(c); } @@ -149,8 +151,8 @@ static void *choices_search_worker(void *data) { struct worker *w = (struct worker *)data; const choices_t *c = w->choices; - size_t start = (w->worker_num) * c->size / w->worker_count; - size_t end = (w->worker_num + 1) * c->size / w->worker_count; + size_t start = (w->worker_num) * c->size / c->worker_count; + size_t end = (w->worker_num + 1) * c->size / c->worker_count; for(size_t i = start; i < end; i++) { if (has_match(w->search, c->strings[i])) { @@ -173,12 +175,10 @@ void choices_search(choices_t *c, const char *search) { abort(); } - int worker_count = 8; - struct worker *workers = calloc(worker_count, sizeof(struct worker)); - for (int i = 0; i < worker_count; i++) { + struct worker *workers = calloc(c->worker_count, sizeof(struct worker)); + for (unsigned int i = 0; i < c->worker_count; i++) { workers[i].choices = c; workers[i].search = search; - workers[i].worker_count = worker_count; workers[i].worker_num = i; workers[i].results = malloc(c->size * sizeof(struct scored_result)); /* FIXME: This is overkill */ if (pthread_create(&workers[i].thread_id, NULL, &choices_search_worker, &workers[i])) { @@ -187,7 +187,7 @@ void choices_search(choices_t *c, const char *search) { } } - for (int i = 0; i < worker_count; i++) { + for (unsigned int i = 0; i < c->worker_count; i++) { struct worker *w = &workers[i]; if (pthread_join(w->thread_id, NULL)) { diff --git a/src/choices.h b/src/choices.h @@ -20,6 +20,8 @@ typedef struct { size_t available; size_t selection; + + unsigned int worker_count; } choices_t; void choices_init(choices_t *c);