Package: grep When don't pass backref parameter to dfaexec(), a DFA state which is built previously may be re-built.
In non-UTF8 locales, when reach a state which mbps aren't empty, exit main loop and call build_state() in dfa.c, even if the state has been already built. That will cause increase of processing time, and waste of a lot of memories. Fortunately, grep program doesn't pass the code in dfa.c unless mblen_buf overflows, since backref parameter is specified when dfaexec() is called with large buffer. Norihiro
>From fba7984fa2a5baff18e1b48611c3d7fb3701255b Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka <[email protected]> Date: Sat, 22 Mar 2014 15:11:52 +0900 Subject: [PATCH] grep: avoid to re-build a state built previously. * src/dfa.c (dfaexec): avoid to re-build a state built previously. --- src/dfa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dfa.c b/src/dfa.c index 5e60cd5..8261849 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -3501,7 +3501,8 @@ dfaexec (struct dfa *d, char const *begin, char *end, if (s >= 0) { - build_state (s, d); + if (!d->trans[s]) + build_state (s, d); trans = d->trans; continue; } -- 1.9.1
