Mercurial > gnulib
changeset 18444:0f7103b2baf0
dfa: save memory for states
* src/dfa (dfaexec_main): Beginning of dfa execution, release caches of
states if dfa has a lot of caches.
author | Norihiro Tanaka <noritnk@kcn.ne.jp> |
---|---|
date | Mon, 10 Oct 2016 23:08:29 +0900 |
parents | 13a96af9b883 |
children | c3bfa3b7b8d2 |
files | lib/dfa.c |
diffstat | 1 files changed, 33 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/dfa.c Mon Oct 10 08:05:36 2016 -0700 +++ b/lib/dfa.c Mon Oct 10 23:08:29 2016 +0900 @@ -3105,6 +3105,39 @@ 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);