From af6a4b83ebdb83f24b6913b372e207bcf245ea0c Mon Sep 17 00:00:00 2001 From: Tom Hinton Date: Thu, 1 Oct 2015 12:16:41 +0100 Subject: Make normal filtering of plain ASCII lines faster This patch adds a field lines_not_ascii to the MenuState structure. The nth entry is 0 unless the nth member of MenuState.lines has a non-ascii codepoint in it. All comparison functions (menu_match_cb type) take an additional argument to tell them if the thing they are matching is not_ascii. They can use this to determine whether to collate and case-fold the input (for non-ascii strings), or whether to use strstr/strcasestr (for ascii strings). The change is not currently implemented for flex matching, due to my laziness. However, it should be a simple enough matter to add. For my large input of 400,000 lines, this reduces typical filtering time to about ten microseconds from about 2 seconds. --- source/dialogs/combi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/dialogs/combi.c') diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 1002de08..8f67cd2f 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -169,7 +169,7 @@ static SwitcherMode combi_mode_result ( int mretv, char **input, unsigned int se } return MODE_EXIT; } -static int combi_mode_match ( char **tokens, const char *input, +static int combi_mode_match ( char **tokens, const char *input, int not_ascii, int case_sensitive, unsigned int index, Switcher *sw ) { CombiModePrivateData *pd = sw->private_data; @@ -178,13 +178,13 @@ static int combi_mode_match ( char **tokens, const char *input, if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) { if ( tokens && input[0] && tokens[0][0] == '!' ) { if ( tokens[0][1] == pd->switchers[i]->name[0] ) { - return pd->switchers[i]->token_match ( &tokens[1], input, case_sensitive, + return pd->switchers[i]->token_match ( &tokens[1], input, not_ascii, case_sensitive, index - pd->starts[i], pd->switchers[i] ); } return 0; } else { - return pd->switchers[i]->token_match ( tokens, input, case_sensitive, + return pd->switchers[i]->token_match ( tokens, input, not_ascii, case_sensitive, index - pd->starts[i], pd->switchers[i] ); } } -- cgit v1.2.3