diff options
author | Norihiro Tanaka <noritnk@kcn.ne.jp> | 2016-10-10 23:08:29 +0900 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-10-10 08:27:11 -0700 |
commit | 2692e23a48e21f6daa029e8af9f1a143b7532f47 (patch) | |
tree | a86b28a87daca34b030c411ae724079832c982f9 /lib/dfa.c | |
parent | 1ef68655809cac8db42ff69a2a7c171863b61357 (diff) | |
download | gnulib-2692e23a48e21f6daa029e8af9f1a143b7532f47.tar.gz |
dfa: save memory for states
* src/dfa (dfaexec_main): Beginning of dfa execution, release caches of
states if dfa has a lot of caches.
Diffstat (limited to 'lib/dfa.c')
-rw-r--r-- | lib/dfa.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -3105,6 +3105,39 @@ dfaexec_main (struct dfa *d, char const *begin, char *end, bool allow_nl, unsigned char saved_end; size_t nlcount = 0; + if (MAX_TRCOUNT <= d->sindex) + { + for (s = d->min_trcount; s < d->sindex; s++) + { + free (d->states[s].elems.elems); + free (d->states[s].mbps.elems); + } + d->sindex = d->min_trcount; + + if (d->trans) + { + for (s = 0; s < d->tralloc; s++) + { + free (d->trans[s]); + free (d->fails[s]); + d->trans[s] = d->fails[s] = NULL; + } + d->trcount = 0; + } + + if (d->localeinfo.multibyte && d->mb_trans) + { + for (s = -1; s < d->tralloc; s++) + { + free (d->mb_trans[s]); + d->mb_trans[s] = NULL; + } + for (s = 0; s < d->min_trcount; s++) + d->states[s].mb_trindex = -1; + d->mb_trcount = 0; + } + } + if (!d->tralloc) { realloc_trans_if_necessary (d, 1); |