grep/grep-2.5.4-dfa-optional.patch
Jaroslav Škarvada d612644be3 - New version: grep-2.5.4 (#502931)
- Fixed typos in %description
- Updated utf-8 patch
- Added dfa-optional patch (#538423)
2010-02-12 14:47:35 +00:00

69 lines
1.7 KiB
Diff

--- ./src/search.c.old 2010-02-12 14:29:01.000000000 +0100
+++ ./src/search.c 2010-02-12 14:29:18.207410166 +0100
@@ -278,6 +278,8 @@
char eol = eolbyte;
int backref, start, len, best_len;
struct kwsmatch kwsm;
+ static int use_dfa;
+ static int use_dfa_checked = 0;
size_t i, ret_val;
#ifdef MBS_SUPPORT
int mb_cur_max = MB_CUR_MAX;
@@ -285,6 +287,26 @@
memset (&mbs, '\0', sizeof (mbstate_t));
#endif /* MBS_SUPPORT */
+ if (!use_dfa_checked)
+ {
+ char *grep_use_dfa = getenv ("GREP_USE_DFA");
+ if (!grep_use_dfa)
+ {
+#ifdef MBS_SUPPORT
+ /* Turn off DFA when processing multibyte input. */
+ use_dfa = (MB_CUR_MAX == 1);
+#else
+ use_dfa = 1;
+#endif /* MBS_SUPPORT */
+ }
+ else
+ {
+ use_dfa = atoi (grep_use_dfa);
+ }
+
+ use_dfa_checked = 1;
+ }
+
buflim = buf + size;
for (beg = end = buf; end < buflim; beg = end)
@@ -353,7 +375,8 @@
#endif /* MBS_SUPPORT */
(kwsm.index < kwset_exact_matches))
goto success;
- if (dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1)
+ if (use_dfa &&
+ dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1)
continue;
}
else
@@ -362,7 +385,9 @@
#ifdef MBS_SUPPORT
size_t bytes_left = 0;
#endif /* MBS_SUPPORT */
- size_t offset = dfaexec (&dfa, beg, buflim - beg, &backref);
+ size_t offset = 0;
+ if (use_dfa)
+ offset = dfaexec (&dfa, beg, buflim - beg, &backref);
if (offset == (size_t) -1)
break;
/* Narrow down to the line we've found. */
@@ -404,7 +429,7 @@
--beg;
}
/* Successful, no backreferences encountered! */
- if (!backref)
+ if (use_dfa && !backref)
goto success;
}
else