diff options
author | Phil Jones <philj56@gmail.com> | 2022-11-28 22:19:12 +0000 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2022-11-28 22:19:12 +0000 |
commit | 3861e8289ae40bac168275ce6f10b231e11baa55 (patch) | |
tree | 30093bb562e9718c60d3d36c9942ce4714c43488 /src/input.c | |
parent | 574b523ab5d9b63a114ac905e5ff8494f4b2f233 (diff) |
Refactor string vector code.
Previously, string vectors were built by reading input line-by line, and
multiple copies of string vectors were made when searching.
Now, input is read into one big buffer, and string vectors only contain
references to the strings in this buffer. This both speeds up reading of
input, and avoids unnecessary copying of strings in various places.
The main downside currently is that input read from stdin is no longer
UTF-8 normalised. This means, for example, that a search for `e` won't
necessarily match `é`. Normalisation is very slow relative to the rest
of tofi, however, and not needed for most use-cases. This could either
be solved by accepting the slowdown, or making this an option, such as
--unicode or --unicode-normalize.
Diffstat (limited to 'src/input.c')
-rw-r--r-- | src/input.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/input.c b/src/input.c index 5864cd1..9be16e9 100644 --- a/src/input.c +++ b/src/input.c @@ -130,13 +130,13 @@ void add_character(struct tofi *tofi, xkb_keycode_t keycode) N_ELEM(buf)); entry->input_utf8_length += len; if (entry->drun) { - struct string_vec results = desktop_vec_filter(&entry->apps, entry->input_utf8, tofi->fuzzy_match); - string_vec_destroy(&entry->results); + struct string_ref_vec results = desktop_vec_filter(&entry->apps, entry->input_utf8, tofi->fuzzy_match); + string_ref_vec_destroy(&entry->results); entry->results = results; } else { - struct string_vec tmp = entry->results; - entry->results = string_vec_filter(&entry->results, entry->input_utf8, tofi->fuzzy_match); - string_vec_destroy(&tmp); + struct string_ref_vec tmp = entry->results; + entry->results = string_ref_vec_filter(&entry->results, entry->input_utf8, tofi->fuzzy_match); + string_ref_vec_destroy(&tmp); } reset_selection(tofi); @@ -154,11 +154,11 @@ void input_refresh_results(struct tofi *tofi) } entry->input_utf8[bytes_written] = '\0'; entry->input_utf8_length = bytes_written; - string_vec_destroy(&entry->results); + string_ref_vec_destroy(&entry->results); if (entry->drun) { entry->results = desktop_vec_filter(&entry->apps, entry->input_utf8, tofi->fuzzy_match); } else { - entry->results = string_vec_filter(&entry->commands, entry->input_utf8, tofi->fuzzy_match); + entry->results = string_ref_vec_filter(&entry->commands, entry->input_utf8, tofi->fuzzy_match); } reset_selection(tofi); |