Re: Ad-filter loading and QRegExp performance
Thiago Macieira <[email protected]> Thu, 1 Feb 2007 14:46:21 +0100
| Newsgroups | gmane.comp.kde.devel.kfm,gmane.comp.kde.devel.optimize |
|---|---|
| Message-ID | <[email protected]> |
--nextPart1535661.HimK5SMSa7 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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. =A0I am not sure of the >> best way to do that. > >=A0A 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= =20 it grows, it must copy the elements to the new array. Tulip classes are=20 somewhat clever about their growth strategy, but if you know beforehand=20 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=20 QRegExp, QList does not store the elements themselves in the vector. It=20 stores a pointer to them. That means one extra malloc(), but no object is=20 copied during resizing. In both cases, avoid detaching at all costs. Always use ConstIterators,=20 constBegin and constEnd (or foreach). =2D-=20 =A0 Thiago Macieira =A0- =A0thiago (AT) macieira.info - thiago (AT) kde.org =A0 =A0 PGP/GPG: 0x6EF45358; fingerprint: =A0 =A0 E067 918B B660 DBD1 105C =A0966C 33F5 F005 6EF4 5358 --nextPart1535661.HimK5SMSa7 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQBFwe8tM/XwBW70U1gRAodUAJ9bPoBTFOypIDyLgeKE3baLrSmcIwCfVqt5 fXu81iMt8PXGP+pdXk9FKoA= =dVKR -----END PGP SIGNATURE----- --nextPart1535661.HimK5SMSa7--