Skip to content

Commit 850d1b7

Browse files
marcmutzQt Cherry-pick Bot
authored and
Qt Cherry-pick Bot
committed
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.5 Change-Id: I1f0ce17cbeb171704f789624ad1be6ef70e58245 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit 75df3a2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit e1d0213)
1 parent e0ae962 commit 850d1b7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/corelib/tools/qarraydataops.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,11 @@ struct QMovableArrayOps
661661

662662
struct Inserter
663663
{
664-
QArrayDataPointer<T> *data;
664+
QArrayDataPointer<T> * const data;
665665
T *displaceFrom;
666-
T *displaceTo;
667-
qsizetype nInserts = 0;
668-
size_t bytes;
666+
T * const displaceTo;
667+
const qsizetype nInserts = 0;
668+
const size_t bytes;
669669

670670
void verifyPost()
671671
{ Q_ASSERT(displaceFrom == displaceTo); }
@@ -680,13 +680,14 @@ struct QMovableArrayOps
680680
::memmove(static_cast<void *>(displaceTo), static_cast<void *>(displaceFrom), bytes);
681681
}
682682
~Inserter() {
683+
auto inserts = nInserts;
683684
if constexpr (!std::is_nothrow_copy_constructible_v<T>) {
684685
if (displaceFrom != displaceTo) {
685686
::memmove(static_cast<void *>(displaceFrom), static_cast<void *>(displaceTo), bytes);
686-
nInserts -= qAbs(displaceFrom - displaceTo);
687+
inserts -= qAbs(displaceFrom - displaceTo);
687688
}
688689
}
689-
data->size += nInserts;
690+
data->size += inserts;
690691
}
691692
Q_DISABLE_COPY(Inserter)
692693

0 commit comments

Comments
 (0)