summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Persch <chpe@gnome.org>2015-10-07 22:15:05 +0200
committerChristian Persch <chpe@gnome.org>2015-10-07 22:15:05 +0200
commit9a774ea964769466c8db6476b9b34dcb67c67245 (patch)
tree444c7a05a5c5caba3e9ea7d85e88869848d0407d
parent664d9f3d7be3690aa35c5cd671d05e3f0e8e09b0 (diff)
downloadvte-9a774ea964769466c8db6476b9b34dcb67c67245.tar.gz
regex: Simplify no-match region calculation
It is only necessary to updated start/end_blank once per regex. Note that with or without the patch, the no-match region sometimes is wrong.
-rw-r--r--src/vte.cc34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/vte.cc b/src/vte.cc
index dc65932c..66d33d83 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -1654,6 +1654,7 @@ vte_terminal_match_check_internal_pcre(VteTerminal *terminal,
PCRE2_SPTR8, PCRE2_SIZE, PCRE2_SIZE, uint32_t,
pcre2_match_data_8 *, pcre2_match_context_8 *);
int r = 0;
+ gssize sblank = G_MINSSIZE, eblank = G_MAXSSIZE;
regex = &g_array_index(terminal->pvt->match_regexes,
struct vte_match_regex,
@@ -1685,7 +1686,6 @@ vte_terminal_match_check_internal_pcre(VteTerminal *terminal,
match_context)) >= 0 || r == PCRE2_ERROR_PARTIAL)) {
gsize ko = offset;
gsize rm_so, rm_eo;
- gssize sblank=G_MINSSIZE, eblank=G_MAXSSIZE;
ovector = pcre2_get_ovector_pointer_8(match_data);
rm_so = ovector[0];
@@ -1754,17 +1754,18 @@ vte_terminal_match_check_internal_pcre(VteTerminal *terminal,
if (ko < rm_so && rm_so < eblank) {
eblank = rm_so;
}
-
- if (sblank > start_blank) {
- start_blank = sblank;
- }
- if (eblank < end_blank) {
- end_blank = eblank;
- }
}
if (G_UNLIKELY(r < PCRE2_ERROR_PARTIAL))
_vte_debug_print(VTE_DEBUG_REGEX, "Unexpected pcre2_match error code: %d\n", r);
+
+ if (sblank > start_blank) {
+ start_blank = sblank;
+ }
+ if (eblank < end_blank) {
+ end_blank = eblank;
+ }
+
}
pcre2_match_data_free_8(match_data);
@@ -1826,6 +1827,8 @@ vte_terminal_match_check_internal_gregex(VteTerminal *terminal,
/* Now iterate over each regex we need to match against. */
for (i = 0; i < terminal->pvt->match_regexes->len; i++) {
+ gint sblank = G_MININT, eblank = G_MAXINT;
+
regex = &g_array_index(terminal->pvt->match_regexes,
struct vte_match_regex,
i);
@@ -1850,7 +1853,6 @@ vte_terminal_match_check_internal_gregex(VteTerminal *terminal,
while (g_match_info_matches(match_info)) {
gint ko = offset;
- gint sblank=G_MININT, eblank=G_MAXINT;
gint rm_so, rm_eo;
if (g_match_info_fetch_pos (match_info, 0, &rm_so, &rm_eo)) {
@@ -1901,19 +1903,19 @@ vte_terminal_match_check_internal_gregex(VteTerminal *terminal,
if (ko < rm_so && rm_so < eblank) {
eblank = rm_so;
}
-
- if (sblank > start_blank) {
- start_blank = sblank;
- }
- if (eblank < end_blank) {
- end_blank = eblank;
- }
}
g_match_info_next(match_info, NULL);
}
g_match_info_free(match_info);
+
+ if (sblank > start_blank) {
+ start_blank = sblank;
+ }
+ if (eblank < end_blank) {
+ end_blank = eblank;
+ }
}
/* Record smallest span where none of the dingus match */