From 75df3a250d84a7e2680a8f229d11eec20b2d3ff0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 4 Mar 2025 14:59:48 +0100 Subject: [PATCH] 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 --- src/corelib/tools/qarraydataops.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index f245c28c464..40859134043 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -634,11 +634,11 @@ public: struct Inserter { - QArrayDataPointer *data; + QArrayDataPointer * 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(displaceTo), static_cast(displaceFrom), bytes); } ~Inserter() { + auto inserts = nInserts; if constexpr (!std::is_nothrow_copy_constructible_v) { if (displaceFrom != displaceTo) { ::memmove(static_cast(displaceFrom), static_cast(displaceTo), bytes); - nInserts -= qAbs(displaceFrom - displaceTo); + inserts -= qAbs(displaceFrom - displaceTo); } } - data->size += nInserts; + data->size += inserts; } Q_DISABLE_COPY(Inserter)