From 3861e8289ae40bac168275ce6f10b231e11baa55 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Mon, 28 Nov 2022 22:19:12 +0000 Subject: Refactor string vector code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/input.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/input.c') 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); -- cgit v1.2.3