]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: save memory for states
authorNorihiro Tanaka <noritnk@kcn.ne.jp>
Mon, 10 Oct 2016 14:08:29 +0000 (23:08 +0900)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 10 Oct 2016 15:27:11 +0000 (08:27 -0700)
* src/dfa (dfaexec_main): Beginning of dfa execution, release caches of
states if dfa has a lot of caches.

lib/dfa.c

index c4dc626b1e8721cbea7845a3c396836b874f4b7c..744a9f1413099617f6c6c9afafc5f6af45e67bb8 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -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);