diff options
author | Phil Jones <philj56@gmail.com> | 2022-11-19 19:33:57 +0000 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2022-11-19 19:33:57 +0000 |
commit | 8ab1b98328d720dec70087f0435210cdd5c67852 (patch) | |
tree | c084a2faf2be548f67450dca5c4d6d92adfee4c1 | |
parent | 5da0579864a13b11bf0808f7f69f7b22f18054b1 (diff) |
Make vector finding functions names clearer.
This adds `_sorted` to the names of `string_vec_find` and
`desktop_vec_find`, to make it clear that these functions require their
input to already be sorted.
Also fix a potential bug from not sorting the list of desktops in drun
mode.
-rw-r--r-- | src/compgen.c | 2 | ||||
-rw-r--r-- | src/desktop_vec.c | 7 | ||||
-rw-r--r-- | src/desktop_vec.h | 2 | ||||
-rw-r--r-- | src/drun.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/string_vec.c | 2 | ||||
-rw-r--r-- | src/string_vec.h | 2 |
7 files changed, 10 insertions, 9 deletions
diff --git a/src/compgen.c b/src/compgen.c index 8421cec..6cc21a2 100644 --- a/src/compgen.c +++ b/src/compgen.c @@ -181,7 +181,7 @@ void compgen_history_sort(struct string_vec *programs, struct history *history) { log_debug("Moving already known programs to the front.\n"); for (size_t i = 0; i < history->count; i++) { - struct scored_string *res = string_vec_find(programs, history->buf[i].name); + struct scored_string *res = string_vec_find_sorted(programs, history->buf[i].name); if (res == NULL) { log_debug("History entry \"%s\" not found.\n", history->buf[i].name); continue; diff --git a/src/desktop_vec.c b/src/desktop_vec.c index 102dd67..a9aa1f7 100644 --- a/src/desktop_vec.c +++ b/src/desktop_vec.c @@ -135,7 +135,7 @@ void desktop_vec_sort(struct desktop_vec *restrict vec) qsort(vec->buf, vec->count, sizeof(vec->buf[0]), cmpdesktopp); } -struct desktop_entry *desktop_vec_find(struct desktop_vec *restrict vec, const char *name) +struct desktop_entry *desktop_vec_find_sorted(struct desktop_vec *restrict vec, const char *name) { /* * Explicitly cast away const-ness, as even though we won't modify the @@ -256,8 +256,9 @@ bool match_current_desktop(char * const *desktop_list, gsize length) } free(tmp); + string_vec_sort(&desktops); for (gsize i = 0; i < length; i++) { - if (string_vec_find(&desktops, desktop_list[i])) { + if (string_vec_find_sorted(&desktops, desktop_list[i])) { return true; } } @@ -346,7 +347,7 @@ bool match_current_desktop(char * const *desktop_list, gsize length) // tmp = xstrdup(desktop_list); // desktop = strtok_r(tmp, ";", &saveptr); // while (desktop != NULL) { -// if (string_vec_find(&desktops, desktop)) { +// if (string_vec_find_sorted(&desktops, desktop)) { // return true; // } // desktop = strtok_r(NULL, ";", &saveptr); diff --git a/src/desktop_vec.h b/src/desktop_vec.h index a731566..760db30 100644 --- a/src/desktop_vec.h +++ b/src/desktop_vec.h @@ -33,7 +33,7 @@ void desktop_vec_add( void desktop_vec_add_file(struct desktop_vec *desktop, const char *id, const char *path); void desktop_vec_sort(struct desktop_vec *restrict vec); -struct desktop_entry *desktop_vec_find(struct desktop_vec *restrict vec, const char *name); +struct desktop_entry *desktop_vec_find_sorted(struct desktop_vec *restrict vec, const char *name); struct string_vec desktop_vec_filter( const struct desktop_vec *restrict vec, const char *restrict substr, @@ -385,7 +385,7 @@ void drun_history_sort(struct desktop_vec *apps, struct history *history) { log_debug("Moving already known apps to the front.\n"); for (size_t i = 0; i < history->count; i++) { - struct desktop_entry *res = desktop_vec_find(apps, history->buf[i].name); + struct desktop_entry *res = desktop_vec_find_sorted(apps, history->buf[i].name); if (res == NULL) { continue; } @@ -963,7 +963,7 @@ static bool do_submit(struct tofi *tofi) * we previously sorted by history count. This needs fixing. */ desktop_vec_sort(&entry->apps); - struct desktop_entry *app = desktop_vec_find(&entry->apps, res); + struct desktop_entry *app = desktop_vec_find_sorted(&entry->apps, res); if (app == NULL) { log_error("Couldn't find application file! This shouldn't happen.\n"); return false; diff --git a/src/string_vec.c b/src/string_vec.c index f5cf899..8c59607 100644 --- a/src/string_vec.c +++ b/src/string_vec.c @@ -138,7 +138,7 @@ void string_vec_uniq(struct string_vec *restrict vec) vec->count = count; } -struct scored_string *string_vec_find(struct string_vec *restrict vec, const char * str) +struct scored_string *string_vec_find_sorted(struct string_vec *restrict vec, const char * str) { return bsearch(&str, vec->buf, vec->count, sizeof(vec->buf[0]), cmpstringp); } diff --git a/src/string_vec.h b/src/string_vec.h index f8ca3e0..f04b385 100644 --- a/src/string_vec.h +++ b/src/string_vec.h @@ -35,7 +35,7 @@ void string_vec_history_sort(struct string_vec *restrict vec, struct history *hi void string_vec_uniq(struct string_vec *restrict vec); -struct scored_string *string_vec_find(struct string_vec *restrict vec, const char *str); +struct scored_string *string_vec_find_sorted(struct string_vec *restrict vec, const char *str); [[nodiscard("memory leaked")]] struct string_vec string_vec_filter( |