QMovableArrayOps::Inserter cleanup [2/3]: mark most data members const

This makes explicit that the only thing that should be changing is
displaceFrom, which tracks the hole-filling process.

Requires rewriting of the dtor a bit, to skip the nInserts
modification.

Pick-to: 6.9 6.8 6.5
Change-Id: I1f0ce17cbeb171704f789624ad1be6ef70e58245
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
Marc Mutz 2025-03-04 14:59:48 +01:00 committed by Ahmad Samir
parent 82d4a81df1
commit 75df3a250d

View File

@ -634,11 +634,11 @@ public:
struct Inserter
{
QArrayDataPointer<T> *data;
QArrayDataPointer<T> * const data;
T *displaceFrom;
T *displaceTo;
qsizetype nInserts = 0;
size_t bytes;
T * const displaceTo;
const qsizetype nInserts = 0;
const size_t bytes;
void verifyPost(T *where)
{ Q_ASSERT(where == displaceTo); }
@ -653,13 +653,14 @@ public:
::memmove(static_cast<void *>(displaceTo), static_cast<void *>(displaceFrom), bytes);
}
~Inserter() {
auto inserts = nInserts;
if constexpr (!std::is_nothrow_copy_constructible_v<T>) {
if (displaceFrom != displaceTo) {
::memmove(static_cast<void *>(displaceFrom), static_cast<void *>(displaceTo), bytes);
nInserts -= qAbs(displaceFrom - displaceTo);
inserts -= qAbs(displaceFrom - displaceTo);
}
}
data->size += nInserts;
data->size += inserts;
}
Q_DISABLE_COPY(Inserter)