[Development] QList for Qt 6

Mutz, Marc marc at kdab.com
Fri May 24 14:09:30 CEST 2019


On 2019-05-24 11:03, Lars Knoll wrote:
[...]
> You conveniently didn’t quote the first part of my answer. I didn’t
> say that. I said I really want to ensure that we get a zero copy
> conversion between QList and QVector where this doesn’t imply
> (possible) incorrectness in the code. That’s the case for all types
> that are smaller than a pointer and movable.

Ok, I'm sorry if I misinterpreted your mail. All too easy with text :)

So, what's the conclusion from that experiment? We can't make QList 
switch between QArrayList and QVector based on properties of the type, 
because that breaks declaring QList<fwd_declared_type>. 'Switch' here 
means anything from a selecting template alias to QList inheriting or 
aggregating QArrayList or QVector, based on the template argument.

So the only solution, if you want zero-copy conversion between QVector 
and Q5List-excl-IndirectLayout is to keep Q5List, remove the padding, 
and add the begin offset optimization to QVector. Then a 
reinterpret_cast of the d-pointer should be enough.

To summarize: zero-cost conversion between QList and QVector means:

1. Make QVector slower for every user (because of the extra memory load 
in calculating begin())
2. Keep QList as-is. It cannot be an alias to QVector/QArrayList, nor 
can it be implemented in terms of either (only at the d-pointer level)

Is it worth the cost? I don't know.

Thanks,
Marc



More information about the Development mailing list