diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2021-11-13 15:18:49 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2021-11-13 15:18:49 +0100 |
commit | 50edb33f1c4b11e7c82c1608f535a8bfd4449269 (patch) | |
tree | 583bf4f6528c3382d4d9ba8d641ed507b46d075d /src | |
parent | c82358c17c1b17fc0bd2e7bd0de4671509a5f7a0 (diff) | |
download | weechat-50edb33f1c4b11e7c82c1608f535a8bfd4449269.zip |
core: speed up eval by storing length of prefix/suffix in eval structure
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-eval.c | 21 | ||||
-rw-r--r-- | src/core/wee-eval.h | 2 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index f8d08e203..03e77460e 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -181,7 +181,7 @@ eval_strstr_level (const char *string, const char *search, { const char *ptr_string; int level, length_search, debug_id; - int length_prefix, length_prefix2, length_suffix, length_suffix2; + int length_prefix2, length_suffix2; ptr_string = NULL; @@ -196,9 +196,6 @@ eval_strstr_level (const char *string, const char *search, length_search = strlen (search); - length_prefix = strlen (eval_context->prefix); - length_suffix = strlen (eval_context->suffix); - length_prefix2 = (extra_prefix) ? strlen (extra_prefix) : 0; length_suffix2 = (extra_suffix) ? strlen (extra_suffix) : 0; @@ -213,10 +210,10 @@ eval_strstr_level (const char *string, const char *search, { ptr_string++; } - else if (strncmp (ptr_string, eval_context->prefix, length_prefix) == 0) + else if (strncmp (ptr_string, eval_context->prefix, eval_context->length_prefix) == 0) { level++; - ptr_string += length_prefix; + ptr_string += eval_context->length_prefix; } else if ((length_prefix2 > 0) && (strncmp (ptr_string, extra_prefix, length_prefix2) == 0)) @@ -224,11 +221,11 @@ eval_strstr_level (const char *string, const char *search, level++; ptr_string += length_prefix2; } - else if (strncmp (ptr_string, eval_context->suffix, length_suffix) == 0) + else if (strncmp (ptr_string, eval_context->suffix, eval_context->length_suffix) == 0) { if (level > 0) level--; - ptr_string += length_suffix; + ptr_string += eval_context->length_suffix; } else if ((length_suffix2 > 0) && (strncmp (ptr_string, extra_suffix, length_suffix2) == 0)) @@ -2426,7 +2423,9 @@ eval_expression (const char *expr, struct t_hashtable *pointers, eval_context->user_vars = user_vars; eval_context->extra_vars_eval = 0; eval_context->prefix = default_prefix; + eval_context->length_prefix = strlen (eval_context->prefix); eval_context->suffix = default_suffix; + eval_context->length_suffix = strlen (eval_context->suffix); eval_context->regex = NULL; eval_context->regex_replacement_index = 1; eval_context->recursion_count = 0; @@ -2473,12 +2472,18 @@ eval_expression (const char *expr, struct t_hashtable *pointers, /* check for custom prefix */ ptr_value = hashtable_get (options, "prefix"); if (ptr_value && ptr_value[0]) + { eval_context->prefix = ptr_value; + eval_context->length_prefix = strlen (eval_context->prefix); + } /* check for custom suffix */ ptr_value = hashtable_get (options, "suffix"); if (ptr_value && ptr_value[0]) + { eval_context->suffix = ptr_value; + eval_context->length_suffix = strlen (eval_context->suffix); + } /* check for regex */ ptr_value = hashtable_get (options, "regex"); diff --git a/src/core/wee-eval.h b/src/core/wee-eval.h index 03b33a421..34e00bc4c 100644 --- a/src/core/wee-eval.h +++ b/src/core/wee-eval.h @@ -76,7 +76,9 @@ struct t_eval_context struct t_hashtable *user_vars; /* user-defined variables */ int extra_vars_eval; /* 1 if extra vars must be evaluated */ const char *prefix; /* prefix (default is "${") */ + int length_prefix; /* length of prefix */ const char *suffix; /* suffix (default is "}") */ + int length_suffix; /* length of suffix */ struct t_eval_regex *regex; /* in case of replace with regex */ int regex_replacement_index; /* replacement index (≥ 1) */ int recursion_count; /* to prevent infinite recursion */ |