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

Mark Gaiser markg85 at gmail.com
Tue Jan 27 09:41:47 CET 2015


On Tue, Jan 27, 2015 at 8:56 AM, Felix morack <felixover at gmail.com> wrote:

> hello,
>
>
> i recently gained a small, but considerable performance boost by switching
> out QList for QVector in some legacy code. This is hindered by the fact
> that Qt itself often returns QList, eg with QMap::values().
>
>
> Is there a reason for this? Why arent QVectors used?
>
>
> A somewhat related question, why is there no QList::reserve()? I guess i
> see how that function might not make much sense from an algorithmic pov,
> but shouldnt it at least be there as a NoOp to make it easy switching
> between data structures?
>
>
> best regards,
>
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150127/8446afec/attachment.html>


More information about the Interest mailing list