[Interest] why does Qt prefer to return QList over QVector?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Tue Jan 27 10:34:57 CET 2015


Il 27/01/2015 09:41, Mark Gaiser ha scritto:
> As far as i know this is for historic reasons. QList used to be faster
> then QVector (someone, please correct me if i'm wrong) in the old days,
> but nowadays (Qt5 era) they prefer QVector over QList. It is as fast or
> faster then QList in nearly every situation. I vaguely remember there
> being one exception where QList was faster, but i don't know the
> exception anymore.

I don't think it has ever been faster. The main reason behind QList is 
to generate less code: all the handling of the backing array is shared 
amongst the specializations. But please refer to Marc Mutz's awesome 
blog posts for more info:

https://marcmutz.wordpress.com/effective-qt/containers/

The other difference with QVector is that QList has a prepend optimization.

> A somewhat related question, why is there no QList::reserve()?

There is, what's missing is resize(). (Fundamentally that "shared part" 
behind QList has no code dealing with shrinking.) I've got a WIP on 
gerrit, if only I get the time to work on it again...

Cheers,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Software Engineer
KDAB (UK) Ltd., a KDAB Group company
Tel. UK +44-1738-450410, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4048 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150127/561d8f4c/attachment.bin>


More information about the Interest mailing list