From 431b52d03f3ccb6a797bd9668df54d9ab6119843 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 4 Mar 2025 14:59:48 +0100 Subject: [PATCH] QMovableArrayOps::Inserter cleanup [1/3]: inline displace() Since the ctor is now the only caller of displace(), we can inline the latter into the former, using ctor-init-list to initialize the members. Also fix decltype(bytes) to be size_t, which is what memmove(), the only user of the value, expects, and ptrdiff_t * sizeof(T) yields (found by GCC -Wnarrowing complaining). Pick-to: 6.8 6.5 Change-Id: I3f93e28eebc6deefee8a182eb71a3b0958718ba0 Reviewed-by: Thiago Macieira (cherry picked from commit 82d4a81df19fe9aff9d3b1790c2b371a3efc0a99) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qarraydataops.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 621ff915ad6..f245c28c464 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -638,14 +638,20 @@ public: T *displaceFrom; T *displaceTo; qsizetype nInserts = 0; - qsizetype bytes; + size_t bytes; void verifyPost(T *where) { Q_ASSERT(where == displaceTo); } explicit Inserter(QArrayDataPointer *d, qsizetype pos, qsizetype n) - : data(d) - { displace(pos, n); } + : data{d}, + displaceFrom{d->ptr + pos}, + displaceTo{displaceFrom + n}, + nInserts{n}, + bytes{(data->size - pos) * sizeof(T)} + { + ::memmove(static_cast(displaceTo), static_cast(displaceFrom), bytes); + } ~Inserter() { if constexpr (!std::is_nothrow_copy_constructible_v) { if (displaceFrom != displaceTo) { @@ -657,18 +663,6 @@ public: } Q_DISABLE_COPY(Inserter) - T *displace(qsizetype pos, qsizetype n) - { - nInserts = n; - T *insertionPoint = data->ptr + pos; - displaceFrom = data->ptr + pos; - displaceTo = displaceFrom + n; - bytes = data->size - pos; - bytes *= sizeof(T); - ::memmove(static_cast(displaceTo), static_cast(displaceFrom), bytes); - return insertionPoint; - } - void insertRange(const T *source, qsizetype n) { T *where = displaceFrom;