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

Marc Mutz marc.mutz at kdab.com
Tue Jul 21 08:11:33 CEST 2015


On Tuesday 21 July 2015 02:48:12 Kevin Kofler wrote:
> IMHO, QList is the safest container to recommend to an inexperienced 
> programmer, because there are very few operations that have a suboptimal 
> complexity class. (Of course, abuse of contains or indexOf/lastIndexOf
> where  a QHash or QMap should be used is problematic, but that's true for
> any list type.) Sure, the constant factor is often not optimal (though in
> common cases such as the implicitly-shared Qt classes, the code is
> actually supposed to do the exact same thing as QVector, so there
> shouldn't be any difference in those cases), but it is much better than
> hitting the worst case of QVector or QLinkedList because you just picked
> what the
> documentation told you without realizing the performance impact.

If you hit the QVector or QLinkedList worst-case, your profiler will pinpoint 
that reliably. No profiler will help you with the creeping pessimisation of 
using QList.

> If we want the most efficient code at all costs, we need to write in 
> assembly, not C++.

So you're comparing the cost of using QVector over QList with that of using 
assembly over C++? In which kind of universe is that a valid simile?

Thanks,
Marc

-- 
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



More information about the Development mailing list