[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO

Smith Martin Martin.Smith at theqtcompany.com
Fri Jul 10 17:00:22 CEST 2015


>This is not premature optimisation. 

It is premature because the entire structure will be removed.

________________________________________
From: development-bounces+martin.smith=theqtcompany.com at qt-project.org <development-bounces+martin.smith=theqtcompany.com at qt-project.org> on behalf of Marc Mutz <marc.mutz at kdab.com>
Sent: Friday, July 10, 2015 5:32 PM
To: development at qt-project.org
Subject: Re: [Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO

On Friday 10 July 2015 14:48:26 Smith Martin wrote:
> but I generally don'[[t try to optimize until I have a working model.

This is not premature optimisation. This is avoiding premature pessimisation
(google it!).

QVector has exactly the same API these days as QList (except that QVector
requires a default ctor and QList doesn't; if something else is missing,
shout), so code using QVector is equally readable as code using QList. If that
is the case, the more efficient alternative is what should naturally flow out
of your fingers.

And another thing: By using a QVector, not only do you avoid an additional
heap allocation per element inserted, you also avoid readers of your code
guessing whether you're using the QList for its list features (like the
QList<Page> in QToolBoxPrivate - go, read it, it's subtle!) or just as a
container.

--
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development


More information about the Development mailing list