diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-06-04 21:06:49 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-07 14:17:55 +0100 |
commit | bf0b4f332a2f1ec9860c610d98cd27e483869bec (patch) | |
tree | 0593f49cd79fea6986fcbcc05ab098e36c6494bb /src/corelib | |
parent | 41287d355b9571db0fbdf5841b31595705af0102 (diff) |
Rename QArrayData::AllocateOptions enum and update some flags
Rename to QArrayData::ArrayOptions in preparation for these flags
being in the array itself, instead of used just for allocating new
ones.
For that reason, rename QArrayData::Default to
DefaultAllocationFlags. And introduce QArray::DefaultRawFlags to mean
the flags needed for creating a raw (static) QArrayData.
Also rename QArrayData::Grow to GrowsForward, so we may add
GrowsBackward in the future.
Change-Id: I536d9b34124f775d53cf810f62d6b0eaada8daef
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 16 | ||||
-rw-r--r-- | src/corelib/text/qbytearray.h | 2 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qarraydata.cpp | 6 | ||||
-rw-r--r-- | src/corelib/tools/qarraydata.h | 32 | ||||
-rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 20 |
7 files changed, 41 insertions, 39 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 4a00c664c0..380730775d 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -1776,7 +1776,7 @@ void QByteArray::resize(int size) d = x; } else { if (d->ref.isShared() || uint(size) + 1u > d->alloc) - reallocData(uint(size) + 1u, d->detachFlags() | Data::Grow); + reallocData(uint(size) + 1u, d->detachFlags() | Data::GrowsForward); if (d->alloc) { d->size = size; d->data()[size] = '\0'; @@ -1803,7 +1803,7 @@ QByteArray &QByteArray::fill(char ch, int size) return *this; } -void QByteArray::reallocData(uint alloc, Data::AllocationOptions options) +void QByteArray::reallocData(uint alloc, Data::ArrayOptions options) { if (d->ref.isShared() || IS_RAW_DATA(d)) { Data *x = Data::allocate(alloc, options); @@ -1901,7 +1901,7 @@ QByteArray &QByteArray::prepend(const char *str, int len) { if (str) { if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) - reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); + reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::GrowsForward); memmove(d->data()+len, d->data(), d->size); memcpy(d->data(), str, len); d->size += len; @@ -1927,7 +1927,7 @@ QByteArray &QByteArray::prepend(const char *str, int len) QByteArray &QByteArray::prepend(char ch) { if (d->ref.isShared() || uint(d->size) + 2u > d->alloc) - reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow); + reallocData(uint(d->size) + 2u, d->detachFlags() | Data::GrowsForward); memmove(d->data()+1, d->data(), d->size); d->data()[0] = ch; ++d->size; @@ -1965,7 +1965,7 @@ QByteArray &QByteArray::append(const QByteArray &ba) *this = ba; } else if (ba.d->size != 0) { if (d->ref.isShared() || uint(d->size + ba.d->size) + 1u > d->alloc) - reallocData(uint(d->size + ba.d->size) + 1u, d->detachFlags() | Data::Grow); + reallocData(uint(d->size + ba.d->size) + 1u, d->detachFlags() | Data::GrowsForward); memcpy(d->data() + d->size, ba.d->data(), ba.d->size); d->size += ba.d->size; d->data()[d->size] = '\0'; @@ -1997,7 +1997,7 @@ QByteArray& QByteArray::append(const char *str) if (str) { const int len = int(strlen(str)); if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) - reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); + reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::GrowsForward); memcpy(d->data() + d->size, str, len + 1); // include null terminator d->size += len; } @@ -2022,7 +2022,7 @@ QByteArray &QByteArray::append(const char *str, int len) len = qstrlen(str); if (str && len) { if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) - reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); + reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::GrowsForward); memcpy(d->data() + d->size, str, len); // include null terminator d->size += len; d->data()[d->size] = '\0'; @@ -2050,7 +2050,7 @@ QByteArray &QByteArray::append(const char *str, int len) QByteArray& QByteArray::append(char ch) { if (d->ref.isShared() || uint(d->size) + 2u > d->alloc) - reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow); + reallocData(uint(d->size) + 2u, d->detachFlags() | Data::GrowsForward); d->data()[d->size++] = ch; d->data()[d->size] = '\0'; return *this; diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 1376e26260..4d56cd93fd 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -445,7 +445,7 @@ public: private: operator QNoImplicitBoolCast() const; Data *d; - void reallocData(uint alloc, Data::AllocationOptions options); + void reallocData(uint alloc, Data::ArrayOptions options); void expand(int i); QByteArray nulTerminated() const; diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index dcdc87181e..5f5b0acd15 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -2351,7 +2351,7 @@ void QString::reallocData(uint alloc, bool grow) { auto allocOptions = d->detachFlags(); if (grow) - allocOptions |= QArrayData::Grow; + allocOptions |= QArrayData::GrowsForward; if (d->ref.isShared() || IS_RAW_DATA(d)) { Data *x = Data::allocate(alloc, allocOptions); diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index ed7dfe2e41..592faf39c3 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -170,7 +170,7 @@ static inline size_t calculateBlockSize(size_t &capacity, size_t objectSize, siz // Calculate the byte size // allocSize = objectSize * capacity + headerSize, but checked for overflow // plus padded to grow in size - if (options & QArrayData::Grow) { + if (options & QArrayData::GrowsForward) { auto r = qCalculateGrowingBlockSize(capacity, objectSize, headerSize); capacity = r.elementCount; return r.size; @@ -188,7 +188,7 @@ static QArrayData *reallocateData(QArrayData *header, size_t allocSize, uint opt } QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, - size_t capacity, AllocationOptions options) noexcept + size_t capacity, ArrayOptions options) noexcept { // Alignment is a power of two Q_ASSERT(alignment >= alignof(QArrayData) @@ -227,7 +227,7 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, } QArrayData *QArrayData::reallocateUnaligned(QArrayData *data, size_t objectSize, size_t capacity, - AllocationOptions options) noexcept + ArrayOptions options) noexcept { Q_ASSERT(data); Q_ASSERT(data->isMutable()); diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index a91dd54262..c2da2767c3 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -76,15 +77,16 @@ struct Q_CORE_EXPORT QArrayData return alloc != 0; } - enum AllocationOption { + enum ArrayOption { CapacityReserved = 0x1, RawData = 0x4, - Grow = 0x8, + GrowsForward = 0x8, - Default = 0 + DefaultAllocationFlags = 0, + DefaultRawFlags = 0 }; - Q_DECLARE_FLAGS(AllocationOptions, AllocationOption) + Q_DECLARE_FLAGS(ArrayOptions, ArrayOption) size_t detachCapacity(size_t newSize) const { @@ -93,17 +95,17 @@ struct Q_CORE_EXPORT QArrayData return newSize; } - AllocationOptions detachFlags() const + ArrayOptions detachFlags() const { - AllocationOptions result; + ArrayOptions result; if (capacityReserved) result |= CapacityReserved; return result; } - AllocationOptions cloneFlags() const + ArrayOptions cloneFlags() const { - AllocationOptions result; + ArrayOptions result; if (capacityReserved) result |= CapacityReserved; return result; @@ -114,9 +116,9 @@ struct Q_CORE_EXPORT QArrayData __attribute__((__malloc__)) #endif static QArrayData *allocate(size_t objectSize, size_t alignment, - size_t capacity, AllocationOptions options = Default) noexcept; + size_t capacity, ArrayOptions options = DefaultAllocationFlags) noexcept; Q_REQUIRED_RESULT static QArrayData *reallocateUnaligned(QArrayData *data, size_t objectSize, - size_t newCapacity, AllocationOptions newOptions = Default) noexcept; + size_t newCapacity, ArrayOptions newOptions = DefaultAllocationFlags) noexcept; static void deallocate(QArrayData *data, size_t objectSize, size_t alignment) noexcept; @@ -130,7 +132,7 @@ struct Q_CORE_EXPORT QArrayData } }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocationOptions) +Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::ArrayOptions) template <class T> struct QTypedArrayData @@ -225,7 +227,7 @@ struct QTypedArrayData class AlignmentDummy { QArrayData header; T data; }; Q_REQUIRED_RESULT static QTypedArrayData *allocate(size_t capacity, - AllocationOptions options = Default) + ArrayOptions options = DefaultAllocationFlags) { Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); void *result = QArrayData::allocate(sizeof(T), @@ -237,10 +239,10 @@ struct QTypedArrayData } static QTypedArrayData *reallocateUnaligned(QTypedArrayData *data, size_t capacity, - AllocationOptions options = Default) + ArrayOptions options = DefaultAllocationFlags) { Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); - void *result = QArrayData::reallocateUnaligned(data, sizeof(T), capacity, options)); + void *result = QArrayData::reallocateUnaligned(data, sizeof(T), capacity, options); #if (defined(Q_CC_GNU) && Q_CC_GNU >= 407) || QT_HAS_BUILTIN(__builtin_assume_aligned) result =__builtin_assume_aligned(result, Q_ALIGNOF(AlignmentDummy)); #endif @@ -254,7 +256,7 @@ struct QTypedArrayData } static QTypedArrayData *fromRawData(const T *data, size_t n, - AllocationOptions options = Default) + ArrayOptions options = DefaultRawFlags) { Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); QTypedArrayData *result = allocate(0, options | RawData); diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index b8a1ef5d68..ffeaff5862 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -155,7 +155,7 @@ public: } private: - Q_REQUIRED_RESULT Data *clone(QArrayData::AllocationOptions options) const + Q_REQUIRED_RESULT Data *clone(QArrayData::ArrayOptions options) const { Data *x = Data::allocate(d->detachCapacity(d->size), options); Q_CHECK_PTR(x); diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 5def2eceb2..3220ba1463 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -307,9 +307,9 @@ public: private: // ### Qt6: remove methods, they are unused - void reallocData(const int size, const int alloc, QArrayData::AllocationOptions options = QArrayData::Default); + void reallocData(const int size, const int alloc, QArrayData::ArrayOptions options = QArrayData::DefaultAllocationFlags); void reallocData(const int sz) { reallocData(sz, d->alloc); } - void realloc(int alloc, QArrayData::AllocationOptions options = QArrayData::Default); + void realloc(int alloc, QArrayData::ArrayOptions options = QArrayData::DefaultAllocationFlags); void freeData(Data *d); void defaultConstruct(T *from, T *to); void copyConstruct(const T *srcFrom, const T *srcTo, T *dstFrom); @@ -422,7 +422,7 @@ void QVector<T>::resize(int asize) if (asize == d->size) return detach(); if (asize > int(d->alloc) || !isDetached()) { // there is not enough space - QArrayData::AllocationOptions opt = asize > int(d->alloc) ? QArrayData::Grow : QArrayData::Default; + QArrayData::ArrayOptions opt = asize > int(d->alloc) ? QArrayData::GrowsForward : QArrayData::DefaultAllocationFlags; realloc(qMax(int(d->alloc), asize), opt); } if (asize < d->size) @@ -580,7 +580,7 @@ QT_WARNING_DISABLE_MSVC(4127) // conditional expression is constant #endif template <typename T> -void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::AllocationOptions options) +void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::ArrayOptions options) { Q_ASSERT(asize >= 0 && asize <= aalloc); Data *x = d; @@ -680,7 +680,7 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo } template<typename T> -void QVector<T>::realloc(int aalloc, QArrayData::AllocationOptions options) +void QVector<T>::realloc(int aalloc, QArrayData::ArrayOptions options) { Q_ASSERT(aalloc >= d->size); Data *x = d; @@ -767,7 +767,7 @@ void QVector<T>::append(const T &t) const bool isTooSmall = uint(d->size + 1) > d->alloc; if (!isDetached() || isTooSmall) { T copy(t); - QArrayData::AllocationOptions opt(isTooSmall ? QArrayData::Grow : QArrayData::Default); + QArrayData::ArrayOptions opt(isTooSmall ? QArrayData::GrowsForward : QArrayData::DefaultAllocationFlags); realloc(isTooSmall ? d->size + 1 : d->alloc, opt); if (QTypeInfo<T>::isComplex) @@ -789,7 +789,7 @@ void QVector<T>::append(T &&t) { const bool isTooSmall = uint(d->size + 1) > d->alloc; if (!isDetached() || isTooSmall) { - QArrayData::AllocationOptions opt(isTooSmall ? QArrayData::Grow : QArrayData::Default); + QArrayData::ArrayOptions opt(isTooSmall ? QArrayData::GrowsForward : QArrayData::DefaultAllocationFlags); realloc(isTooSmall ? d->size + 1 : d->alloc, opt); } @@ -820,7 +820,7 @@ typename QVector<T>::iterator QVector<T>::insert(iterator before, size_type n, c if (n != 0) { const T copy(t); if (!isDetached() || d->size + n > int(d->alloc)) - realloc(d->size + n, QArrayData::Grow); + realloc(d->size + n, QArrayData::GrowsForward); if (!QTypeInfoQuery<T>::isRelocatable) { T *b = d->end(); T *i = d->end() + n; @@ -853,7 +853,7 @@ typename QVector<T>::iterator QVector<T>::insert(iterator before, T &&t) const auto offset = std::distance(d->begin(), before); if (!isDetached() || d->size + 1 > int(d->alloc)) - realloc(d->size + 1, QArrayData::Grow); + realloc(d->size + 1, QArrayData::GrowsForward); if (!QTypeInfoQuery<T>::isRelocatable) { T *i = d->end(); T *j = i + 1; @@ -961,7 +961,7 @@ QVector<T> &QVector<T>::operator+=(const QVector &l) uint newSize = d->size + l.d->size; const bool isTooSmall = newSize > d->alloc; if (!isDetached() || isTooSmall) { - QArrayData::AllocationOptions opt(isTooSmall ? QArrayData::Grow : QArrayData::Default); + QArrayData::ArrayOptions opt(isTooSmall ? QArrayData::GrowsForward : QArrayData::DefaultAllocationFlags); realloc(isTooSmall ? newSize : d->alloc, opt); } |