mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
(mc_search_prepare): cache result.
mc_search_struct: add new member prepared.result to keep the result of the mc_search_prepare() first call. It can be used to check a regexp before call of mc_search_run() in a loop. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
975bf17d3b
commit
0222169206
@ -107,8 +107,11 @@ typedef struct mc_search_struct
|
||||
|
||||
/* private data */
|
||||
|
||||
/* prepared */
|
||||
GPtrArray *prepared_conditions;
|
||||
struct
|
||||
{
|
||||
GPtrArray *conditions;
|
||||
gboolean result;
|
||||
} prepared;
|
||||
|
||||
/* original search string */
|
||||
gchar *original;
|
||||
|
@ -364,13 +364,13 @@ mc_search__regex_found_cond (mc_search_t * lc_mc_search, GString * search_str)
|
||||
{
|
||||
gsize loop1;
|
||||
|
||||
for (loop1 = 0; loop1 < lc_mc_search->prepared_conditions->len; loop1++)
|
||||
for (loop1 = 0; loop1 < lc_mc_search->prepared.conditions->len; loop1++)
|
||||
{
|
||||
mc_search_cond_t *mc_search_cond;
|
||||
mc_search__found_cond_t ret;
|
||||
|
||||
mc_search_cond =
|
||||
(mc_search_cond_t *) g_ptr_array_index (lc_mc_search->prepared_conditions, loop1);
|
||||
(mc_search_cond_t *) g_ptr_array_index (lc_mc_search->prepared.conditions, loop1);
|
||||
|
||||
if (!mc_search_cond->regex_handle)
|
||||
continue;
|
||||
|
@ -188,8 +188,8 @@ mc_search_free (mc_search_t * lc_mc_search)
|
||||
#endif
|
||||
g_free (lc_mc_search->error_str);
|
||||
|
||||
if (lc_mc_search->prepared_conditions != NULL)
|
||||
mc_search__conditions_free (lc_mc_search->prepared_conditions);
|
||||
if (lc_mc_search->prepared.conditions != NULL)
|
||||
mc_search__conditions_free (lc_mc_search->prepared.conditions);
|
||||
|
||||
#ifdef SEARCH_TYPE_GLIB
|
||||
if (lc_mc_search->regex_match_info != NULL)
|
||||
@ -211,6 +211,9 @@ mc_search_prepare (mc_search_t * lc_mc_search)
|
||||
{
|
||||
GPtrArray *ret;
|
||||
|
||||
if (lc_mc_search->prepared.conditions != NULL)
|
||||
return lc_mc_search->prepared.result;
|
||||
|
||||
ret = g_ptr_array_new ();
|
||||
#ifdef HAVE_CHARSET
|
||||
if (lc_mc_search->is_all_charsets)
|
||||
@ -256,9 +259,10 @@ mc_search_prepare (mc_search_t * lc_mc_search)
|
||||
lc_mc_search->original_len,
|
||||
str_detect_termencoding ()));
|
||||
#endif
|
||||
lc_mc_search->prepared_conditions = ret;
|
||||
lc_mc_search->prepared.conditions = ret;
|
||||
lc_mc_search->prepared.result = (lc_mc_search->error == MC_SEARCH_E_OK);
|
||||
|
||||
return (lc_mc_search->error == MC_SEARCH_E_OK);
|
||||
return lc_mc_search->prepared.result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -299,7 +303,7 @@ mc_search_run (mc_search_t * lc_mc_search, const void *user_data,
|
||||
|
||||
mc_search_set_error (lc_mc_search, MC_SEARCH_E_OK, NULL);
|
||||
|
||||
if ((lc_mc_search->prepared_conditions == NULL) && !mc_search_prepare (lc_mc_search))
|
||||
if (!mc_search_prepare (lc_mc_search))
|
||||
return FALSE;
|
||||
|
||||
switch (lc_mc_search->search_type)
|
||||
|
Loading…
Reference in New Issue
Block a user