diff options
author | Paolo Bonzini <bonzini@gnu.org> | 2011-06-28 09:07:44 +0200 |
---|---|---|
committer | Paolo Bonzini <bonzini@gnu.org> | 2012-01-03 10:40:08 +0100 |
commit | 3e13407d4cfcbac44a9a50a419a1d33ee2205788 (patch) | |
tree | dfd0704c067478a0a919b63e879254baf3e886f9 | |
parent | 9f9829ffae8e4b9bd3370154209ae9c04b4c5208 (diff) | |
download | grep-3e13407d4cfcbac44a9a50a419a1d33ee2205788.tar.gz |
dfa: move nalloc to position_set structure
* src/dfa.c (position_set): Add alloc.
(alloc_position_set): Initialize it.
(dfaanalyze): Use it instead of the nalloc array or nelem.
-rw-r--r-- | src/dfa.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -247,6 +247,7 @@ typedef struct { position *elems; /* Elements of this position set. */ int nelem; /* Number of elements in this set. */ + size_t alloc; /* Number of elements allocated in ELEMS. */ } position_set; /* Sets of leaves are also stored as arrays. */ @@ -1835,6 +1836,7 @@ static void alloc_position_set (position_set *s, size_t size) { MALLOC(s->elems, size); + s->alloc = size; s->nelem = 0; } @@ -2103,7 +2105,6 @@ dfaanalyze (struct dfa *d, int searchflag) position *firstpos; /* Array where firstpos elements are stored. */ int *nlastpos; /* Element count stack for lastpos sets. */ position *lastpos; /* Array where lastpos elements are stored. */ - int *nalloc; /* Sizes of arrays allocated to follow sets. */ position_set tmp; /* Temporary set for merging sets. */ position_set merged; /* Result of merging sets. */ int wants_newline; /* True if some position wants newline info. */ @@ -2135,7 +2136,6 @@ dfaanalyze (struct dfa *d, int searchflag) o_nlast = nlastpos; MALLOC(lastpos, d->nleaves); o_lastpos = lastpos, lastpos += d->nleaves; - CALLOC(nalloc, d->tindex); alloc_position_set(&merged, d->nleaves); CALLOC(d->follows, d->tindex); @@ -2163,7 +2163,7 @@ dfaanalyze (struct dfa *d, int searchflag) { merge(&tmp, &d->follows[pos[j].index], &merged); REALLOC_IF_NECESSARY(d->follows[pos[j].index].elems, - nalloc[pos[j].index], merged.nelem); + d->follows[pos[j].index].alloc, merged.nelem); copy(&merged, &d->follows[pos[j].index]); } @@ -2183,7 +2183,7 @@ dfaanalyze (struct dfa *d, int searchflag) { merge(&tmp, &d->follows[pos[j].index], &merged); REALLOC_IF_NECESSARY(d->follows[pos[j].index].elems, - nalloc[pos[j].index], merged.nelem); + d->follows[pos[j].index].alloc, merged.nelem); copy(&merged, &d->follows[pos[j].index]); } @@ -2243,7 +2243,6 @@ dfaanalyze (struct dfa *d, int searchflag) firstpos->constraint = lastpos->constraint = NO_CONSTRAINT; /* Allocate the follow set for this position. */ - nalloc[i] = 1; alloc_position_set(&d->follows[i], nalloc[i]); break; } @@ -2292,8 +2291,8 @@ dfaanalyze (struct dfa *d, int searchflag) #endif copy(&d->follows[i], &merged); epsclosure(&merged, d); - if (d->follows[i].nelem < merged.nelem) - REALLOC(d->follows[i].elems, merged.nelem); + REALLOC_IF_NECESSARY(d->follows[i].elems, d->follows[i].alloc, + merged.nelem); copy(&merged, &d->follows[i]); } @@ -2321,7 +2320,6 @@ dfaanalyze (struct dfa *d, int searchflag) free(o_firstpos); free(o_nlast); free(o_lastpos); - free(nalloc); free(merged.elems); } |