[Development] QVector reserve counterproductive?

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Sun Mar 4 14:20:21 CET 2018


Am 04.03.2018 um 10:03 schrieb Christian Ehrlicher:
> 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?)
The off-by-one idea was wrong. moveTo() will add another point to 
elements - therefore reserve(d_func()->elements.size() + polygon.size()) 
is correct.
Maybe the best idea here would be to simply remove the reserve() calls 
and let QVector do what it is made for... :)


Christian



More information about the Development mailing list