diff options
author | Paolo Bonzini <bonzini@gnu.org> | 2011-06-28 09:02:51 +0200 |
---|---|---|
committer | Paolo Bonzini <bonzini@gnu.org> | 2012-01-03 10:39:53 +0100 |
commit | d4cc62b45e115aa72db69a06451afed9bd69a64d (patch) | |
tree | f04836c66f698547d7895512b877d348a01252df /src | |
parent | afa0155946715cddc921cc5556bff1ca2100507a (diff) | |
download | grep-d4cc62b45e115aa72db69a06451afed9bd69a64d.tar.gz |
dfa: introduce alloc_position_set
* src/dfa.c (alloc_position_set): New function, use it throughout.
Diffstat (limited to 'src')
-rw-r--r-- | src/dfa.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -1831,6 +1831,13 @@ copy (position_set const *src, position_set *dst) dst->nelem = src->nelem; } +static void +alloc_position_set (position_set *s, size_t size) +{ + MALLOC(s->elems, size); + s->nelem = 0; +} + /* Insert position P in set S. S is maintained in sorted order on decreasing index. If there is already an entry in S with P.index then merge (logically-OR) P's constraints into the one in S. @@ -1934,7 +1941,7 @@ state_index (struct dfa *d, position_set const *s, int newline, int letter) /* We'll have to create a new state. */ REALLOC_IF_NECESSARY(d->states, d->salloc, d->sindex + 1); d->states[i].hash = hash; - MALLOC(d->states[i].elems.elems, s->nelem); + alloc_position_set(&d->states[i].elems, s->nelem); copy(s, &d->states[i].elems); d->states[i].newline = newline; d->states[i].letter = letter; @@ -2129,7 +2136,7 @@ dfaanalyze (struct dfa *d, int searchflag) MALLOC(lastpos, d->nleaves); o_lastpos = lastpos, lastpos += d->nleaves; CALLOC(nalloc, d->tindex); - MALLOC(merged.elems, d->nleaves); + alloc_position_set(&merged, d->nleaves); CALLOC(d->follows, d->tindex); @@ -2237,7 +2244,7 @@ dfaanalyze (struct dfa *d, int searchflag) /* Allocate the follow set for this position. */ nalloc[i] = 1; - MALLOC(d->follows[i].elems, nalloc[i]); + alloc_position_set(&d->follows[i], nalloc[i]); break; } #ifdef DEBUG @@ -2405,7 +2412,7 @@ dfastate (int s, struct dfa *d, int trans[]) must put it to d->states[s].mbps, which contains the positions which can match with a single character not a byte. */ if (d->states[s].mbps.nelem == 0) - MALLOC(d->states[s].mbps.elems, d->states[s].elems.nelem); + alloc_position_set(&d->states[s].mbps, d->states[s].elems.nelem); insert(pos, &(d->states[s].mbps)); continue; } @@ -2502,8 +2509,8 @@ dfastate (int s, struct dfa *d, int trans[]) } } - MALLOC(follows.elems, d->nleaves); - MALLOC(tmp.elems, d->nleaves); + alloc_position_set(&follows, d->nleaves); + alloc_position_set(&tmp, d->nleaves); /* If we are a searching matcher, the default transition is to a state containing the positions of state 0, otherwise the default transition @@ -3119,8 +3126,7 @@ transit_state (struct dfa *d, int s, unsigned char const **pp) } /* This state has some operators which can match a multibyte character. */ - follows.nelem = 0; - MALLOC(follows.elems, d->nleaves); + alloc_position_set(&follows, d->nleaves); /* `maxlen' may be longer than the length of a character, because it may not be a character but a (multi character) collating element. |