Paolo Bonzini wrote:
> * src/dfa.c (position_set): Add alloc.
> (alloc_posset): Initialize it.
> (dfaanalyze): Use it instead of the nalloc array or nelem.
> ---
> src/dfa.c | 16 +++++++---------
> 1 files changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/src/dfa.c b/src/dfa.c
> index 4644cab..03676b0 100644
> --- a/src/dfa.c
> +++ b/src/dfa.c
> @@ -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_posset (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. */
Nice (I see what's coming :-).
Having a separate array of lengths like that was fragile.
ACK.