Skip to content

Commit

Permalink
fixup! Ensure correctness while typing a query fast
Browse files Browse the repository at this point in the history
  • Loading branch information
mptre committed Dec 30, 2017
1 parent fa4d551 commit 352dee2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct choice {
static int choicecmp(const void *, const void *);
static void delete_between(char *, size_t, size_t, size_t);
static char *eager_strpbrk(const char *, const char *);
static int filter_choices(size_t, int);
static int filter_choices(size_t);
static char *get_choices(void);
static enum key get_key(const char **);
static void handle_sigwinch(int);
Expand Down Expand Up @@ -325,11 +325,12 @@ selected_choice(void)
choices_count = choices.length;
query_grew = 0;
if (dofilter) {
dofilter = 0;
if (filter_choices(choices_count, query_length > 0))
selection = yscroll = 0;
else
if (filter_choices(choices_count)) {
dofilter = selection = yscroll = 0;
dochoices = 1;
} else {
dochoices = 0;
}
}

tty_putp(cursor_invisible, 0);
Expand Down Expand Up @@ -533,14 +534,13 @@ selected_choice(void)
}

/*
* Filter the first nchoices number of choices using the current query.
* If intr is non-zero, regularly check for new user input and abort the
* filtering. This improves the performance when the cardinality of the choices
* is large.
* Filter the first nchoices number of choices using the current query and
* regularly check for new user input and abort the filtering. This improves the
* performance when the cardinality of the choices is large.
* Returns non-zero if the filtering was not aborted.
*/
int
filter_choices(size_t nchoices, int intr)
filter_choices(size_t nchoices)
{
struct choice *c;
struct pollfd pfd;
Expand All @@ -560,7 +560,7 @@ filter_choices(size_t nchoices, int intr)
c->score = (double)query_length/match_length/c->length;
}

if (intr && i > 0 && i % 50 == 0) {
if (i > 0 && i % 50 == 0) {
pfd.fd = fileno(tty_in);
pfd.events = POLLIN;
if ((nready = poll(&pfd, 1, 0)) == -1)
Expand Down

0 comments on commit 352dee2

Please sign in to comment.