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 <thiago.macieira@intel.com> (cherry picked from commit 82d4a81df19fe9aff9d3b1790c2b371a3efc0a99) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9566a199d4
commit
431b52d03f
@ -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<T> *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<void *>(displaceTo), static_cast<void *>(displaceFrom), bytes);
|
||||
}
|
||||
~Inserter() {
|
||||
if constexpr (!std::is_nothrow_copy_constructible_v<T>) {
|
||||
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<void *>(displaceTo), static_cast<void *>(displaceFrom), bytes);
|
||||
return insertionPoint;
|
||||
}
|
||||
|
||||
void insertRange(const T *source, qsizetype n)
|
||||
{
|
||||
T *where = displaceFrom;
|
||||
|
Loading…
x
Reference in New Issue
Block a user