[Development] QList

Thiago Macieira thiago.macieira at intel.com
Sat Mar 18 19:30:35 CET 2017


Em sábado, 18 de março de 2017, às 05:54:20 PDT, André Pönitz escreveu:
> Aliasing QList to QVector might be a feasible option, or maybe replacing
> QList implementation by QVector's, and replacing QVector by something
> not reference-counted.

My plan (which is still not discussed properly and not proven to be feasible) 
is to provide both referece-counted and non-counted versions of QVector, 
QString and QByteArray.

QVector (and, in fact, all the containers) is easy because it's a template in 
the first place. Performing std::move from QtExclusive::QVector (name to be 
discussed) to QVector transfers the array and starts the reference counting; 
std::move in the other direction also transfers if the reference count is 
still 1, copying otherwise. That allows code like:

QVector<MyType> someFunction()	// out-of-line
{
	QtExclusive::QVector<MyType> vector;
	[ operate and populate vector ]
	return vector;		// automatic move
}

in user code:
	QtExclusive::QVector<MyType> vector = someFunction();	// automatic move
	[ mutate some more ]

The objecitve is that the mutating code in [] above runs without having the 
compiler generate superfluous checks for the reference count which we know to 
be 1 and emit dead code for the detach() function. This allows high-
performance code for sections that really need it.

Why not std::vector? Because of the ability to put it back into shared mode, 
which requires the internals between the exclusively-owning and the reference-
counting containers to address the data the same way.

For QString and QByteArray, it gets a little more difficult because they are not 
templates. The current thinking -- and again, no proof attempted that this is 
actually feasible -- is to have:

class QStringView		- has all the const functions
class QString : public QStringView	- adds the mutating functions
class QtExclusive::QString : public QString

The out-of-line code in the exclusive version can override the public 
functions from QString and mark them noexcept, since the reference count is 
guaranteed to be 1 (yes, that's a narrow-contract noexcept). More importantly, 
the inline non-const data() function in the exclusive version can return the 
pointer without checking for detach().

Hmm... I can actually start this now. Don't need to wait for Qt 6.

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




More information about the Development mailing list