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:
parent
82d4a81df1
commit
75df3a250d
@ -634,11 +634,11 @@ public:
|
|||||||
|
|
||||||
struct Inserter
|
struct Inserter
|
||||||
{
|
{
|
||||||
QArrayDataPointer<T> *data;
|
QArrayDataPointer<T> * const data;
|
||||||
T *displaceFrom;
|
T *displaceFrom;
|
||||||
T *displaceTo;
|
T * const displaceTo;
|
||||||
qsizetype nInserts = 0;
|
const qsizetype nInserts = 0;
|
||||||
size_t bytes;
|
const size_t bytes;
|
||||||
|
|
||||||
void verifyPost(T *where)
|
void verifyPost(T *where)
|
||||||
{ Q_ASSERT(where == displaceTo); }
|
{ Q_ASSERT(where == displaceTo); }
|
||||||
@ -653,13 +653,14 @@ public:
|
|||||||
::memmove(static_cast<void *>(displaceTo), static_cast<void *>(displaceFrom), bytes);
|
::memmove(static_cast<void *>(displaceTo), static_cast<void *>(displaceFrom), bytes);
|
||||||
}
|
}
|
||||||
~Inserter() {
|
~Inserter() {
|
||||||
|
auto inserts = nInserts;
|
||||||
if constexpr (!std::is_nothrow_copy_constructible_v<T>) {
|
if constexpr (!std::is_nothrow_copy_constructible_v<T>) {
|
||||||
if (displaceFrom != displaceTo) {
|
if (displaceFrom != displaceTo) {
|
||||||
::memmove(static_cast<void *>(displaceFrom), static_cast<void *>(displaceTo), bytes);
|
::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)
|
Q_DISABLE_COPY(Inserter)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user