Move the reallocate() method from QArrayDataPointer to the Ops class

And only implement it for QPodArrayOps, as that's the only case where
we should be using it.

Change-Id: If48f3e4b142c322d3451309d6d1cf68aee569ea2
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2019-11-16 16:22:36 +01:00
parent ca8b2a3632
commit 1480aa895b
4 changed files with 12 additions and 8 deletions

View File

@ -1673,7 +1673,7 @@ void QByteArray::reallocData(uint alloc, Data::ArrayOptions options)
dd.data()[dd.size] = 0;
d = dd;
} else {
d.reallocate(alloc, options);
d->reallocate(alloc, options);
}
}

View File

@ -2367,7 +2367,7 @@ void QString::reallocData(uint alloc, bool grow)
dd.data()[dd.size] = 0;
d = dd;
} else {
d.reallocate(alloc, allocOptions);
d->reallocate(alloc, allocOptions);
}
}

View File

@ -62,6 +62,9 @@ template <class T>
struct QPodArrayOps
: public QArrayDataPointer<T>
{
private:
typedef QTypedArrayData<T> Data;
public:
typedef typename QArrayDataPointer<T>::parameter_type parameter_type;
void appendInitialize(size_t newSize)
@ -228,6 +231,13 @@ struct QPodArrayOps
}
return true;
}
void reallocate(qsizetype alloc, typename Data::ArrayOptions options)
{
auto pair = Data::reallocateUnaligned(this->d, this->ptr, alloc, options);
this->d = pair.first;
this->ptr = pair.second;
}
};
QT_WARNING_POP

View File

@ -199,12 +199,6 @@ public:
typename Data::ArrayOptions detachFlags() const noexcept { return d->detachFlags(); }
typename Data::ArrayOptions cloneFlags() const noexcept { return d->cloneFlags(); }
void reallocate(uint alloc, typename Data::ArrayOptions options)
{
auto pair = Data::reallocateUnaligned(d, ptr, alloc, options);
d = pair.first;
ptr = pair.second;
}
Data *d_ptr() { return d; }
private: