[Intel-gfx] [PATCH i-g-t 1/3] stats: Allow the underlying arrays to grow at will

Damien Lespiau damien.lespiau at intel.com
Sat Jun 27 11:06:55 PDT 2015


On Sat, Jun 27, 2015 at 06:15:42PM +0100, Chris Wilson wrote:
> > +static void igt_stats_ensure_capacity(igt_stats_t *stats,
> > +				      unsigned int n_additional_values)
> > +{
> > +	unsigned int new_n_values = stats->n_values + n_additional_values;
> > +	unsigned int new_capacity;
> > +
> > +	if (new_n_values <= stats->capacity)
> > +		return;
> > +
> > +	new_capacity = get_new_capacity(new_n_values);
> > +	stats->values = realloc(stats->values,
> > +				sizeof(*stats->values) * new_capacity);
> > +	igt_assert(stats->values);
> > +
> > +	stats->capacity = new_capacity;
> > +
> > +	if (!stats->sorted)
> > +		return;
> > +
> > +	stats->sorted = realloc(stats->sorted,
> > +				sizeof(*stats->values) * new_capacity);
> > +	igt_assert(stats->sorted);
> 
> There isn't any point in preserving the sorted array when pushing new
> values. Might as well just free here and allocate again when required.

Indeed, push the whole thing so far with this change.

-- 
Damien


More information about the Intel-gfx mailing list