Ad-filter loading and QRegExp performance

Thiago Macieira thiago at kde.org
Thu Feb 1 13:46:21 GMT 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: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20070201/90542575/attachment.sig>


More information about the kfm-devel mailing list