[Development] Wishes for C++ standard or compilers

Thiago Macieira thiago.macieira at intel.com
Wed Mar 29 18:10:01 CEST 2017

On quarta-feira, 29 de março de 2017 08:44:35 PDT Thiago Macieira wrote:
> Ok, so I guess we can easily benchmark this by making the Qt containers
> forget about the movable property, then benchmark the load time of a large
> application like Qt Creator. Unfortunately, this means recompiling
> everything, since containers are inlined everywhere. It's easy (a two-line
> change in qtypeinfo.h), but takes times.

Ok, not so easy because QVector does not implement detaching by moves. Here's 
what it looks like for me:

    const size_t newSize = size() + std::distance(i1, i2);
    const bool isTooSmall = newSize > d->allocatedCapacity();
    const bool isOverlapping = d->begin() <= i1 && i2 <= d->end();
    if (isTooSmall || d->needsDetach() || Q_UNLIKELY(isOverlapping)) {
        typename Data::ArrayOptions flags = d->detachFlags();
        if (isTooSmall)
            flags |= Data::GrowsForward;
        DataPointer detached(Data::allocate(d->detachCapacity(newSize), 
        detached->copyAppend(constBegin(), constEnd());
        detached->copyAppend(i1, i2);
    } else {
        // we're detached and we can just move data around
        d->copyAppend(i1, i2);

I'd need to insert a third branch, splitting the isTooSmall case from the 
d->needsDetach() one. Then we could do moves.

This needs to be implemented in the other containers too before we can 

Q1: Where's this code which you've pasted? 
It's QGenericArray

Q2: Where's the handling of movable types?
Hidden behind QArrayDataPointer, see your qarraydataops.h for copyAppend. This 
is actually exception-safe.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Development mailing list