Use the QByteArray::DataPointer typedef instead of QByteArrayData

The goal here is to move things over to QArrayDataPointer. This prepares
for it.

Change-Id: I32f54a47594274799600c618f7341c200ceaa306
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Lars Knoll 2019-11-13 18:59:09 +01:00
parent 8da5d35ae8
commit 8e34d49201
7 changed files with 15 additions and 15 deletions

View File

@ -53,7 +53,6 @@ QT_BEGIN_NAMESPACE
class QByteArray;
struct QArrayData;
struct QByteArrayData;
class QString;

View File

@ -746,7 +746,7 @@ QByteArray qUncompress(const uchar* data, int nbytes)
case Z_OK: {
Q_ASSERT(len <= alloc);
Q_UNUSED(alloc);
QByteArrayData dataPtr = { d.take(), pair.second, uint(len) };
QByteArray::DataPointer dataPtr = { d.take(), pair.second, uint(len) };
pair.second[len] = '\0';
return QByteArray(dataPtr);
}
@ -3101,7 +3101,7 @@ QByteArray QByteArray::mid(int pos, int len) const
case QContainerImplHelper::Empty:
{
auto alloc = Data::allocate(0);
QByteArrayData empty = { alloc.first, alloc.second, 0 };
QByteArray::DataPointer empty = { alloc.first, alloc.second, 0 };
return QByteArray(empty);
}
case QContainerImplHelper::Full:
@ -4416,7 +4416,7 @@ QByteArray QByteArray::number(double n, char f, int prec)
QByteArray QByteArray::fromRawData(const char *data, int size)
{
QByteArrayData x;
QByteArray::DataPointer x;
if (!data) {
x.d = Data::sharedNull();
x.b = Data::sharedNullData();

View File

@ -136,10 +136,14 @@ struct QByteArrayData
class Q_CORE_EXPORT QByteArray
{
public:
using DataPointer = QByteArrayData;
private:
typedef QTypedArrayData<char> Data;
DataPointer d;
public:
enum Base64Option {
Base64Encoding = 0,
Base64UrlEncoding = 1,
@ -417,14 +421,14 @@ public:
int length() const { return int(d.size); }
bool isNull() const;
explicit inline QByteArray(const QByteArrayData &dd)
inline DataPointer &data_ptr() { return d; }
explicit inline QByteArray(const DataPointer &dd)
: d(dd)
{
}
private:
operator QNoImplicitBoolCast() const;
QByteArrayData d;
void reallocData(uint alloc, Data::ArrayOptions options);
void expand(int i);
QByteArray nulTerminated() const;
@ -440,9 +444,6 @@ private:
friend class QString;
friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes);
public:
typedef QByteArrayData DataPtr;
inline DataPtr &data_ptr() { return d; }
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QByteArray::Base64Options)

View File

@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
enum {
// Define as enum to force inlining. Don't expose MaxAllocSize in a public header.
MaxByteArraySize = MaxAllocSize - sizeof(std::remove_pointer<QByteArray::DataPtr>::type)
MaxByteArraySize = MaxAllocSize - sizeof(std::remove_pointer<QByteArray::DataPointer>::type)
};
QT_END_NAMESPACE

View File

@ -5148,7 +5148,7 @@ QByteArray QString::toLatin1_helper_inplace(QString &s)
// Swap the d pointers.
// Kids, avert your eyes. Don't try this at home.
QByteArrayData ba_d = {
QByteArray::DataPointer ba_d = {
s.d.d,
reinterpret_cast<char *>(s.d.b),
length

View File

@ -106,7 +106,7 @@ public:
static QBitArray fromBits(const char *data, qsizetype len);
public:
typedef QByteArray::DataPtr DataPtr;
typedef QByteArray::DataPointer DataPtr;
inline DataPtr &data_ptr() { return d.data_ptr(); }
};

View File

@ -150,12 +150,12 @@ private slots:
};
static const QArrayData staticDataFlags = { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 };
static const QByteArrayData staticStandard = {
static const QByteArray::DataPointer staticStandard = {
static_cast<QTypedArrayData<char> *>(const_cast<QArrayData *>(&staticDataFlags)),
const_cast<char *>("data"),
4
};
static const QByteArrayData staticNotNullTerminated = {
static const QByteArray::DataPointer staticNotNullTerminated = {
static_cast<QTypedArrayData<char> *>(const_cast<QArrayData *>(&staticDataFlags)),
const_cast<char *>("dataBAD"),
4
@ -167,7 +167,7 @@ QByteArray verifyZeroTermination(const QByteArray &ba)
{
// This test does some evil stuff, it's all supposed to work.
QByteArray::DataPtr baDataPtr = const_cast<QByteArray &>(ba).data_ptr();
QByteArray::DataPointer baDataPtr = const_cast<QByteArray &>(ba).data_ptr();
// Skip if isStatic() or fromRawData(), as those offer no guarantees
if (baDataPtr.d->isStatic() || baDataPtr.d->flags & QArrayData::RawDataType)