Why do moest DUContext functions return a QVector and most DUChain use QList?

Milian Wolff mail at milianw.de
Sun Oct 25 22:23:11 UTC 2009

On Sunday 25 October 2009 23:09:07 David Nolden wrote:
> Am Sonntag 25 Oktober 2009 23:00:46 schrieb Milian Wolff:
> > Hi there, especially David once again :)
> >
> > Could you elaborate why most of the DUContext methods return a QVector of
> >
> > pointers, and not a QList? To quote the documentation:
> > > For most purposes, QList is the right class to use. Operations like
> > > prepend() and insert() are usually faster than with QVector because of
> > > the way QList stores its items in memory (see Algorithmic Complexity
> > > for details), and its index-based API is more convenient than
> > > QLinkedList's iterator-based API. It also expands to less code in your
> > > executable.
> >
> > And (emphasise added)
> >
> > > If you want the items to occupy adjacent memory positions, or if your
> > > items are **larger than a pointer** and you want to avoid the overhead
> > > of allocating them on the heap individually at insertion time, then use
> > > QVector.
> >
> > There are lots of methods that return lists of pointers in a QVector. If
> > I read the docs, I'd say those should be QLists? Of course things like
> > importedParentContexts should stay the same.
> A QVector is always faster and takes less memory than a QList, and since
>  the duchain handles very light-weight objects, that does count there.
> In some places also QVector is used mainly because in the background the
>  data is saved in a QVector, so that the function can return a "const
>  QVector<...>&" instead of copying the object over.
> QList is a "one fits all" container that is good for most usecases, but not
> when maximum performance is required. Ideally the whole duchain would not
>  use any of those high-level container classes at all.

Great, thanks for the clarification.
Milian Wolff
mail at milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20091025/0b8f151a/attachment.sig>

More information about the KDevelop-devel mailing list