[Development] QList for Qt 6
lars.knoll at qt.io
Fri May 24 14:22:32 CEST 2019
> On 24 May 2019, at 14:09, Mutz, Marc via Development <development at qt-project.org> wrote:
> 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.
That’s basically the conclusion.
> 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())
Possibly, but I think a lot of this depends on how QVector looks in Qt 6. Thiago had a series of patches for that, that we’ll need to take into account. I vaguely recall that he once mentioned that he could do the prepend optimisation without additional cost.
> 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)
It would require changes to QList’s implementation, but those should be relatively straightforward.
> Is it worth the cost? I don't know.
I at least don’t want to do this now, as long as I know QVector might be changing as well (because operations on the d-pointer level could mean that the code would need to be changed.
So to adjust plans, I’ll leave it with the renaming of QList to QArrayList for now, and make QList an alias to QVector while we’re working on Qt 6. Once we know QVector has it’s final form, we can then revisit QList.
More information about the Development