(mc_search__run_regex): optimization

...for case where there is no MC_SEARCH_CB_INVALID or MC_SEARCH_CB_SKIP
return codes (for search from file manager), so we can copy line
at regex buffer all at once.

Thanks Sergey Naumov <sknaumov@gmail.com> for the original patch.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2013-08-09 09:22:24 +04:00
parent 9ea1ed08c6
commit bb2f5d35f3
3 changed files with 48 additions and 36 deletions

View File

@ -47,8 +47,6 @@ gchar *mc_search__recode_str (const char *, gsize, const char *, const char *, g
gchar *mc_search__get_one_symbol (const char *, const char *, gsize, gboolean *); gchar *mc_search__get_one_symbol (const char *, const char *, gsize, gboolean *);
mc_search_cbret_t mc_search__get_char (mc_search_t *, const void *, gsize, int *);
GString *mc_search__tolower_case_str (const char *, const char *, gsize); GString *mc_search__tolower_case_str (const char *, const char *, gsize);
GString *mc_search__toupper_case_str (const char *, const char *, gsize); GString *mc_search__toupper_case_str (const char *, const char *, gsize);

View File

@ -2,11 +2,12 @@
Search text engine. Search text engine.
Common share code for module. Common share code for module.
Copyright (C) 2009, 2011 Copyright (C) 2009, 2011, 2013
The Free Software Foundation, Inc. The Free Software Foundation, Inc.
Written by: Written by:
Slava Zanko <slavazanko@gmail.com>, 2009. Slava Zanko <slavazanko@gmail.com>, 2009, 2011
Andrew Borodin <aborodin@vmail.ru>, 2013
This file is part of the Midnight Commander. This file is part of the Midnight Commander.
@ -140,22 +141,6 @@ mc_search__get_one_symbol (const char *charset, const char *str, gsize str_len,
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
mc_search_cbret_t
mc_search__get_char (mc_search_t * lc_mc_search, const void *user_data, gsize current_pos,
int *current_char)
{
unsigned char *data;
if (lc_mc_search->search_fn != NULL)
return lc_mc_search->search_fn (user_data, current_pos, current_char);
data = (unsigned char *) user_data;
*current_char = (int) data[current_pos];
return (*current_char == 0) ? MC_SEARCH_CB_ABORT : MC_SEARCH_CB_OK;
}
/* --------------------------------------------------------------------------------------------- */
GString * GString *
mc_search__tolower_case_str (const char *charset, const char *str, gsize str_len) mc_search__tolower_case_str (const char *charset, const char *str, gsize str_len)
{ {

View File

@ -2,12 +2,13 @@
Search text engine. Search text engine.
Regex search Regex search
Copyright (C) 2009, 2011 Copyright (C) 2009, 2011, 2013
The Free Software Foundation, Inc. The Free Software Foundation, Inc.
Written by: Written by:
Slava Zanko <slavazanko@gmail.com>, 2009,2010,2011 Slava Zanko <slavazanko@gmail.com>, 2009, 2010, 2011
Vitaliy Filippov <vitalif@yourcmc.ru>, 2011 Vitaliy Filippov <vitalif@yourcmc.ru>, 2011
Andrew Borodin <aborodin@vmail.ru>, 2013
This file is part of the Midnight Commander. This file is part of the Midnight Commander.
@ -806,28 +807,56 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
g_string_set_size (lc_mc_search->regex_buffer, 0); g_string_set_size (lc_mc_search->regex_buffer, 0);
lc_mc_search->start_buffer = current_pos; lc_mc_search->start_buffer = current_pos;
while (TRUE) if (lc_mc_search->search_fn != NULL)
{ {
int current_chr = '\n'; /* stop search symbol */ int current_chr;
ret = mc_search__get_char (lc_mc_search, user_data, current_pos, &current_chr); do
if (ret == MC_SEARCH_CB_ABORT) {
break; /* stop search symbol */
current_chr = '\n';
if (ret == MC_SEARCH_CB_INVALID) ret = lc_mc_search->search_fn (user_data, current_pos, &current_chr);
continue;
current_pos++; if (ret == MC_SEARCH_CB_ABORT)
break;
if (ret == MC_SEARCH_CB_SKIP) if (ret == MC_SEARCH_CB_INVALID)
continue; continue;
virtual_pos++; current_pos++;
g_string_append_c (lc_mc_search->regex_buffer, (char) current_chr); if (ret == MC_SEARCH_CB_SKIP)
continue;
if ((char) current_chr == '\n' || virtual_pos > end_search) virtual_pos++;
break;
g_string_append_c (lc_mc_search->regex_buffer, (char) current_chr);
}
while ((char) current_chr != '\n' && virtual_pos <= end_search);
}
else
{
char current_chr;
/* optimization for standard case (for search from file manager)
* where there is no MC_SEARCH_CB_INVALID or MC_SEARCH_CB_SKIP
* return codes, so we can copy line at regex buffer all at once
*/
do
{
current_chr = ((char *) user_data)[current_pos];
if (current_chr == '\0')
break;
current_pos++;
}
while (current_chr != '\n' && current_pos <= end_search);
/* use virtual_pos as index of start of current chunk */
g_string_append_len (lc_mc_search->regex_buffer, (char *) user_data + virtual_pos,
current_pos - virtual_pos);
virtual_pos = current_pos;
} }
switch (mc_search__regex_found_cond (lc_mc_search, lc_mc_search->regex_buffer)) switch (mc_search__regex_found_cond (lc_mc_search, lc_mc_search->regex_buffer))