[Development] Container refactor update

Thiago Macieira thiago.macieira at intel.com
Thu Jun 21 11:51:53 CEST 2012


On quinta-feira, 21 de junho de 2012 09.36.29, Marc Mutz wrote:
> > But I want QList to always use realloc. If your type can't be realloc'ed,
> > then QList should indirect.
> 
> What's the rationale for this design choice?

Because it's the current design. All I'm doing is remove the overhead of void* 
slots and expanding the size to include our typical types.

> But whatever it may be: May I ask you to reconsider?

Yes. The benchmark just posted (10000x allocating new) is a very important 
thing to consider.

I'm not saying that I'll do it, but I'll think about it.

> The movable trait (as in Q_MOVABLE_TYPE, not T&&) is nothing a compiler can
> automatically detect, not even theoretically (consider out-of-line copy
> ctors, e.g.).
> 
> So when you say "T is movable", what you really mean is "T is _declared_
> movable by the user".

Yes, that's what I mean.

> The fact that T needs to be declared movable for QList<T> to not use
> per-element free-store allocations then means that the Qt *default*
> container performs "horribly" (quoting yourself) for *all* types except if
> the user takes *manual* action (which might not be easy to do if the type
> in question doesn't have yet a Qt dependency, e.g. if it comes from a
> third-party library; there'll be no got place to put the required
> Q_DECLARE_TYPEINFO).
> 
> I consider this API the wrong way around, don't you? :)

If you put it that way, yes.

The original goal of having QList store pointers was to be very quick on 
reallocations. If it knows that its array is always movable, it can hardcode 
calls to realloc, instead of malloc a new array and copy/move the items. The 
result is that mutating a list of any type is very quick.

In other words: QList is optimised for mutating a list (appending, prepending, 
inserting in the middle, popping from the ends, erasing from the middle).

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120621/c83bd02b/attachment.sig>


More information about the Development mailing list