[Development] QVector reserve counterproductive?

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Sun Mar 4 10:03:40 CET 2018


Am 03.03.2018 um 23:22 schrieb Martins, Sérgio:
> On 2018-03-03 20:38, Christian Ehrlicher wrote:
>
>> But it looks like reserve()
>> allocates *exactly* the amount of elements given.
>
> Actually that qpainterpath code is off-by-one, it should be:
> d_func()->elements.reserve(d_func()->elements.size() + polygon.size() 
> - 1);
>
> which also fixes the performance problem (by luck, in that specific 
> benchmark). Please test.
You're correct - this fixes the problem. Looks like the growth strategy 
is only applied when the current capacity == current size and not when 
the current capacity is slightly higher... good to know (and should 
maybe be documented?)

Will create a patch for qpainterpath soon.

Thx,
Christian



More information about the Development mailing list