Ad-filter loading and QRegExp performance

Thiago Macieira thiago at kde.org
Thu Feb 1 14:46:21 CET 2007


Lubos Lunak wrote:
>> Initially I tried replacing QVector<QRegExp> with QVector<QRegExp*>
>> instead, but I realised that KHTMLSettings needs to be copied, and so
>> these pointers would need to be shared somehow.  I am not sure of the
>> best way to do that.
>
> A simpler way should be storing also QVector<QString>, initially have
>QVector<QRegExp> empty and fill it only when it's needed for the first
> time.

Note that QVector stores the elements themselves in the vector. Every time 
it grows, it must copy the elements to the new array. Tulip classes are 
somewhat clever about their growth strategy, but if you know beforehand 
how many items you'll need, you can tell it. It should help a lot.

Also note that QList does not have this problem. For a complex type like 
QRegExp, QList does not store the elements themselves in the vector. It 
stores a pointer to them. That means one extra malloc(), but no object is 
copied during resizing.

In both cases, avoid detaching at all costs. Always use ConstIterators, 
constBegin and constEnd (or foreach).

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-optimize/attachments/20070201/90542575/attachment.pgp 


More information about the Kde-optimize mailing list