[Kde-pim] KDE/kdepimlibs/akonadi

Marc Mutz marc at kdab.net
Fri Apr 11 11:42:30 BST 2008


On Friday April 11 2008 09:46, Volker Krause wrote:
> On Friday 11 April 2008 08:55:45 Marc Mutz wrote:
> > On Thursday April 10 2008 17:35, Tobias Koenig wrote:
> > > SVN commit 795521 by tokoe:
> > >
> > > Change all QList<QByteArray> to QSet<QByteArray> for itemParts
> >
> > This is a bad idea. A set doesn't pay it's weight for small numbers of
> > items. In the vast majority of cases, it's faster to use a sorted
> > vector/qlist instread of a set. A set is node-based, while a (q)list is
> > simply an array. Locality of reference and malloc-free appends ruin set's
> > day.
>
> Right, performance-wise it's probably not the best choice, but it provides
> exactly the semantics we want here: no duplicates, order doesn't matter.
> That's why we decided to use it instead of a list. The performance impact
> should be limited since these sets are not created very frequently (which
> is the expensive part AFAIU), but mostly passed around and checked to
> contain a specific value. So, I would rather enforce correctness here and
> keep the set, especially since this is not an implementation detail but
> public API.
<snip>

Right, the passing around is not a problem. Neither is the creation, if it's 
done infrequently. It's the checking that counts here. Checking is much 
slower in sets than in sorted vectors. Locality of reference. It might be a 
good idea to not use a naked container here, but wrap it in a class:

class MessagePartSet {
   QList<QByteArray> parts;
public:
   // ...ctors...
   bool containsPart( const QByteArray & part ) const;
   void addPart( const QByteArray & part );
   void removePart( const QByteArray & part );
};

Thanks,
Marc

-- 
Marc Mutz - marc at kdab.com, mutz at kde.org - Klarälvdalens Datakonsult AB
Platform-independent software solutions - www.kdab.com info at kdab.com
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list