From 2a31249560845dd65ffcd20f6991b522af39821b Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Sat, 24 May 2014 09:30:07 +0900 Subject: [PATCH 1/2] dfa: avoid to clear a transition table for initial state If number of DFA states reaches at 1024, all transition tables are cleared in build_state() in order to avoid out-of-memory. However, for initial state that shouldn't be done, because it's always used. * src/dfa.c (build_state): Transition and failure tables for initial state isn't cleared. --- src/dfa.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dfa.c b/src/dfa.c index 70dc046..792edf3 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -2850,16 +2850,18 @@ build_state (state_num s, struct dfa *d) /* Set an upper limit on the number of transition tables that will ever exist at once. 1024 is arbitrary. The idea is that the frequently used transition tables will be quickly rebuilt, whereas the ones that - were only needed once or twice will be cleared away. */ + were only needed once or twice will be cleared away. By the way, + transition table for initial state isn't cleared, because it's always + used. */ if (d->trcount >= 1024) { - for (i = 0; i < d->tralloc; ++i) + for (i = 1; i < d->tralloc; ++i) { free (d->trans[i]); free (d->fails[i]); d->trans[i] = d->fails[i] = NULL; } - d->trcount = 0; + d->trcount = 1; } ++d->trcount; -- 1.9.3