diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2020-09-07 15:33:46 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2020-09-10 17:31:31 +0200 |
commit | 781ecbfc6f1346db5c08ce972dc1ff64dd003dd0 (patch) | |
tree | f77e0e38f2a411cb3c2ae2a3a53c966735ed6e20 /src/corelib/text | |
parent | ec7e680c5007345c34542a57bd2ac344fb112063 (diff) |
QString/QBA: change realloc*Data signatures to use qsizetype
Changed reallocData, reallocGrowData signatures to use qsizetype
instead of size_t
Change-Id: Iebe7def5430d3d3f4660e19cb6c12612543c5abc
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 12 | ||||
-rw-r--r-- | src/corelib/text/qbytearray.h | 10 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 20 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 10 |
4 files changed, 26 insertions, 26 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 284b508e4a..04df7a5eb8 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -1644,7 +1644,7 @@ void QByteArray::resize(qsizetype size) const auto capacityAtEnd = capacity() - d.freeSpaceAtBegin(); if (d->needsDetach() || size > capacityAtEnd) - reallocData(size_t(size), d->detachFlags() | Data::GrowsForward); + reallocData(size, d->detachFlags() | Data::GrowsForward); d.size = size; if (d->allocatedCapacity()) d.data()[size] = 0; @@ -1668,7 +1668,7 @@ QByteArray &QByteArray::fill(char ch, qsizetype size) return *this; } -void QByteArray::reallocData(size_t alloc, Data::ArrayOptions options) +void QByteArray::reallocData(qsizetype alloc, Data::ArrayOptions options) { if (!alloc) { d = DataPointer::fromRawData(&_empty, 0); @@ -1681,7 +1681,7 @@ void QByteArray::reallocData(size_t alloc, Data::ArrayOptions options) const bool slowReallocatePath = d.freeSpaceAtBegin() > 0; if (d->needsDetach() || slowReallocatePath) { - DataPointer dd(Data::allocate(alloc, options), qMin(qsizetype(alloc), d.size)); + DataPointer dd(Data::allocate(alloc, options), qMin(alloc, d.size)); if (dd.size > 0) ::memcpy(dd.data(), d.data(), dd.size); dd.data()[dd.size] = 0; @@ -1691,13 +1691,13 @@ void QByteArray::reallocData(size_t alloc, Data::ArrayOptions options) } } -void QByteArray::reallocGrowData(size_t alloc, Data::ArrayOptions options) +void QByteArray::reallocGrowData(qsizetype alloc, Data::ArrayOptions options) { if (!alloc) // expected to always allocate alloc = 1; if (d->needsDetach()) { - const auto newSize = qMin(qsizetype(alloc), d.size); + const auto newSize = qMin(alloc, d.size); DataPointer dd(DataPointer::allocateGrow(d, alloc, newSize, options)); dd->copyAppend(d.data(), d.data() + newSize); dd.data()[dd.size] = 0; @@ -1866,7 +1866,7 @@ QByteArray& QByteArray::append(char ch) { const bool shouldGrow = d->shouldGrowBeforeInsert(d.end(), 1); if (d->needsDetach() || size() + 1 > capacity() || shouldGrow) - reallocGrowData(size_t(size()) + 1u, d->detachFlags() | Data::GrowsForward); + reallocGrowData(size() + 1, d->detachFlags() | Data::GrowsForward); d->copyAppend(1, ch); d.data()[d.size] = '\0'; return *this; diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index ec5fbf5a02..8855f25dac 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -460,8 +460,8 @@ public: } private: - void reallocData(size_t alloc, Data::ArrayOptions options); - void reallocGrowData(size_t alloc, Data::ArrayOptions options); + void reallocData(qsizetype alloc, Data::ArrayOptions options); + void reallocGrowData(qsizetype alloc, Data::ArrayOptions options); void expand(qsizetype i); QByteArray nulTerminated() const; @@ -513,7 +513,7 @@ inline const char *QByteArray::data() const inline const char *QByteArray::constData() const { return data(); } inline void QByteArray::detach() -{ if (d->needsDetach()) reallocData(size_t(size()), d->detachFlags()); } +{ if (d->needsDetach()) reallocData(size(), d->detachFlags()); } inline bool QByteArray::isDetached() const { return !d->isShared(); } inline QByteArray::QByteArray(const QByteArray &a) noexcept : d(a.d) @@ -524,7 +524,7 @@ inline qsizetype QByteArray::capacity() const { return qsizetype(d->constAllocat inline void QByteArray::reserve(qsizetype asize) { if (d->needsDetach() || asize > capacity() - d->freeSpaceAtBegin()) { - reallocData(qMax(size_t(size()), size_t(asize)), d->detachFlags() | Data::CapacityReserved); + reallocData(qMax(size(), asize), d->detachFlags() | Data::CapacityReserved); } else { d->setFlag(Data::CapacityReserved); } @@ -535,7 +535,7 @@ inline void QByteArray::squeeze() if ((d->flags() & Data::CapacityReserved) == 0) return; if (d->needsDetach() || size() < capacity()) { - reallocData(size_t(size()), d->detachFlags() & ~Data::CapacityReserved); + reallocData(size(), d->detachFlags() & ~Data::CapacityReserved); } else { d->clearFlag(Data::CapacityReserved); } diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 263dd0f302..f34a100747 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -2384,7 +2384,7 @@ void QString::resize(qsizetype size) const auto capacityAtEnd = capacity() - d.freeSpaceAtBegin(); if (d->needsDetach() || size > capacityAtEnd) - reallocData(size_t(size), d->detachFlags() | Data::GrowsForward); + reallocData(size, d->detachFlags() | Data::GrowsForward); d.size = size; if (d->allocatedCapacity()) d.data()[size] = 0; @@ -2462,7 +2462,7 @@ void QString::resize(qsizetype size, QChar fillChar) \sa reserve(), capacity() */ -void QString::reallocData(size_t alloc, Data::ArrayOptions allocOptions) +void QString::reallocData(qsizetype alloc, Data::ArrayOptions allocOptions) { if (!alloc) { d = DataPointer::fromRawData(&_empty, 0); @@ -2475,7 +2475,7 @@ void QString::reallocData(size_t alloc, Data::ArrayOptions allocOptions) const bool slowReallocatePath = d.freeSpaceAtBegin() > 0; if (d->needsDetach() || slowReallocatePath) { - DataPointer dd(Data::allocate(alloc, allocOptions), qMin(qsizetype(alloc), d.size)); + DataPointer dd(Data::allocate(alloc, allocOptions), qMin(alloc, d.size)); if (dd.size > 0) ::memcpy(dd.data(), d.data(), dd.size * sizeof(QChar)); dd.data()[dd.size] = 0; @@ -2485,13 +2485,13 @@ void QString::reallocData(size_t alloc, Data::ArrayOptions allocOptions) } } -void QString::reallocGrowData(size_t alloc, Data::ArrayOptions options) +void QString::reallocGrowData(qsizetype alloc, Data::ArrayOptions options) { if (!alloc) // expected to always allocate alloc = 1; if (d->needsDetach()) { - const auto newSize = qMin(qsizetype(alloc), d.size); + const auto newSize = qMin(alloc, d.size); DataPointer dd(DataPointer::allocateGrow(d, alloc, newSize, options)); dd->copyAppend(d.data(), d.data() + newSize); dd.data()[dd.size] = 0; @@ -2777,7 +2777,7 @@ QString &QString::append(const QString &str) } else { const bool shouldGrow = d->shouldGrowBeforeInsert(d.end(), str.d.size); if (d->needsDetach() || size() + str.size() > capacity() || shouldGrow) - reallocGrowData(uint(size() + str.size()), + reallocGrowData(size() + str.size(), d->detachFlags() | Data::GrowsForward); d->copyAppend(str.d.data(), str.d.data() + str.d.size); d.data()[d.size] = '\0'; @@ -2797,7 +2797,7 @@ QString &QString::append(const QChar *str, qsizetype len) if (str && len > 0) { const bool shouldGrow = d->shouldGrowBeforeInsert(d.end(), len); if (d->needsDetach() || size() + len > capacity() || shouldGrow) - reallocGrowData(uint(size() + len), d->detachFlags() | Data::GrowsForward); + reallocGrowData(size() + len, d->detachFlags() | Data::GrowsForward); static_assert(sizeof(QChar) == sizeof(char16_t), "Unexpected difference in sizes"); // the following should be safe as QChar uses char16_t as underlying data const char16_t *char16String = reinterpret_cast<const char16_t *>(str); @@ -2819,7 +2819,7 @@ QString &QString::append(QLatin1String str) qsizetype len = str.size(); const bool shouldGrow = d->shouldGrowBeforeInsert(d.end(), len); if (d->needsDetach() || size() + len > capacity() || shouldGrow) - reallocGrowData(size_t(size() + len), d->detachFlags() | Data::GrowsForward); + reallocGrowData(size() + len, d->detachFlags() | Data::GrowsForward); if (d.freeSpaceAtBegin() == 0) { // fast path char16_t *i = d.data() + d.size; @@ -4011,7 +4011,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) if (!iterator.hasNext()) // no matches at all return *this; - reallocData(size_t(d.size), d->detachFlags()); + reallocData(d.size, d->detachFlags()); qsizetype numCaptures = re.captureCount(); @@ -6101,7 +6101,7 @@ const ushort *QString::utf16() const { if (!d->isMutable()) { // ensure '\0'-termination for ::fromRawData strings - const_cast<QString*>(this)->reallocData(size_t(d.size), d->detachFlags()); + const_cast<QString*>(this)->reallocData(d.size, d->detachFlags()); } return reinterpret_cast<const ushort *>(d.data()); } diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 62826d67e2..e11457461c 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -951,8 +951,8 @@ private: friend inline bool operator< (QChar, QLatin1String) noexcept; friend inline bool operator> (QChar, QLatin1String) noexcept; - void reallocData(size_t alloc, Data::ArrayOptions options); - void reallocGrowData(size_t alloc, Data::ArrayOptions options); + void reallocData(qsizetype alloc, Data::ArrayOptions options); + void reallocGrowData(qsizetype alloc, Data::ArrayOptions options); static int compare_helper(const QChar *data1, qsizetype length1, const QChar *data2, qsizetype length2, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; @@ -1167,7 +1167,7 @@ inline QString::~QString() {} inline void QString::reserve(qsizetype asize) { if (d->needsDetach() || asize >= capacity() - d.freeSpaceAtBegin()) { - reallocData(size_t(qMax(asize, size())), d->detachFlags() | Data::CapacityReserved); + reallocData(qMax(asize, size()), d->detachFlags() | Data::CapacityReserved); } else { d->setFlag(Data::CapacityReserved); } @@ -1177,8 +1177,8 @@ inline void QString::squeeze() { if ((d->flags() & Data::CapacityReserved) == 0) return; - if (d->needsDetach() || int(d.size) < capacity()) { - reallocData(size_t(d.size), d->detachFlags() & ~Data::CapacityReserved); + if (d->needsDetach() || d.size < capacity()) { + reallocData(d.size, d->detachFlags() & ~Data::CapacityReserved); } else { d->clearFlag(Data::CapacityReserved); } |