[Development] Important recent changes in QList/QString/QByteArray

Ville Voutilainen ville.voutilainen at gmail.com
Wed Sep 2 10:04:37 CEST 2020


On Tue, 1 Sep 2020 at 20:44, Giuseppe D'Angelo via Development
<development at qt-project.org> wrote:
>
> Il 01/09/20 19:33, Thiago Macieira ha scritto:
> > All non-const functions that may detach should be coded so they DO detach.
> > That is, after any and all non-const functions, the refcount of the container
> > should be 1.
>
> This is the contract, and it's OK. I don't think however that this is
> what was intended by OP. Rather, that calling a non-const function may
> repack/reallocate a QCC (*), causing invalidation of all references and
> iterators, even if the container was NOT shared in the first place.
>
> Did I misunderstand the problem?

Interesting. I'm curious what sort of repacking happens on erase, and why
it wasn't done in such a way that e.g. QVector is 4 pointers instead
of 3, so that
the element storage wouldn't necessarily be at the beginning of the
allocated block;
in that approach, a pop_front would merely bump the begin, and erase
still wouldn't
invalidate anything before the erased position.


More information about the Development mailing list