]>
Commit | Line | Data |
---|---|---|
e0c0fa61 AM |
1 | The DFA algorithm is slow with mutlibytes characters. |
2 | This patch disables the DFA algorithm, but it can be re-enabled by setting | |
3 | the GREP_USE_DFA environment variable. | |
4 | ||
5 | This patch requires 64-egf-speedup.patch | |
6 | --- src/search.c.orig 2005-09-06 22:22:17.000000000 +0200 | |
7 | +++ src/search.c 2005-09-06 22:25:41.000000000 +0200 | |
8 | @@ -326,6 +326,8 @@ | |
9 | char eol = eolbyte; | |
10 | int backref, start, len; | |
11 | struct kwsmatch kwsm; | |
12 | + static int use_dfa; | |
13 | + static int use_dfa_checked = 0; | |
14 | size_t i, ret_val; | |
15 | #ifdef MBS_SUPPORT | |
16 | int mb_cur_max = MB_CUR_MAX; | |
17 | @@ -333,6 +335,26 @@ | |
18 | memset (&mbs, '\0', sizeof (mbstate_t)); | |
19 | #endif /* MBS_SUPPORT */ | |
20 | ||
21 | + if (!use_dfa_checked) | |
22 | + { | |
23 | + char *grep_use_dfa = getenv ("GREP_USE_DFA"); | |
24 | + if (!grep_use_dfa) | |
25 | + { | |
26 | +#ifdef MBS_SUPPORT | |
27 | + /* Turn off DFA when processing multibyte input. */ | |
28 | + use_dfa = (MB_CUR_MAX == 1); | |
29 | +#else | |
30 | + use_dfa = 1; | |
31 | +#endif /* MBS_SUPPORT */ | |
32 | + } | |
33 | + else | |
34 | + { | |
35 | + use_dfa = atoi (grep_use_dfa); | |
36 | + } | |
37 | + | |
38 | + use_dfa_checked = 1; | |
39 | + } | |
40 | + | |
41 | buflim = buf + size; | |
42 | ||
43 | for (beg = end = buf; end < buflim; beg = end) | |
44 | @@ -400,7 +422,8 @@ | |
45 | #endif /* MBS_SUPPORT */ | |
46 | (kwsm.index < kwset_exact_matches)) | |
47 | goto success; | |
48 | - if (dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1) | |
49 | + if (use_dfa && | |
50 | + dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1) | |
51 | continue; | |
52 | } | |
53 | else | |
54 | @@ -409,7 +432,9 @@ | |
55 | #ifdef MBS_SUPPORT | |
56 | size_t bytes_left = 0; | |
57 | #endif /* MBS_SUPPORT */ | |
58 | - size_t offset = dfaexec (&dfa, beg, buflim - beg, &backref); | |
59 | + size_t offset = 0; | |
60 | + if (use_dfa) | |
61 | + offset = dfaexec (&dfa, beg, buflim - beg, &backref); | |
62 | if (offset == (size_t) -1) | |
63 | break; | |
64 | /* Narrow down to the line we've found. */ | |
65 | @@ -451,7 +476,7 @@ | |
66 | --beg; | |
67 | } | |
68 | /* Successful, no backreferences encountered! */ | |
69 | - if (!backref) | |
70 | + if (use_dfa && !backref) | |
71 | goto success; | |
72 | } | |
73 | else |