diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2020-10-07 15:32:57 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2020-10-08 16:52:28 +0200 |
commit | 6c7ed4c013393ce414f02fe4c9a88ebebeb3e47d (patch) | |
tree | f43c4567312b87a03e3e227f9c2a5fe565041f9b /src/corelib/tools | |
parent | 6443c2215ee5c7d085fe84c7a271b70ea1185d3b (diff) |
Make QADP capacity functions use qsizetype instead of size_t
Change types returned and accepted by capacity-related QArrayDataPointer
functions to qsizetype:
1) QArrayData (underlying d-ptr) works with qsizetype
2) QArrayDataPointer::size is of type qsizetype
3) All higher level classes that use QADP (e.g. containers)
cast capacity to qsizetype in their methods
Additionally, fixed newly appeared warnings through qtbase
Change-Id: I899408decfbf2ce9d527be7e8b7f6382875148fc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 18 | ||||
-rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 6 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 12 |
3 files changed, 18 insertions, 18 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index b0834ad762..9626f4eeff 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -1186,7 +1186,7 @@ protected: { Q_ASSERT(this->isMutable() || required == 0); Q_ASSERT(!this->isShared() || required == 0); - Q_ASSERT(required <= this->constAllocatedCapacity() - this->size); + Q_ASSERT(required <= size_t(this->constAllocatedCapacity() - this->size)); using MoveOps = std::conditional_t<QTypeInfo<T>::isRelocatable, RelocatableMoveOps, @@ -1279,7 +1279,7 @@ protected: // container. This is insert-specific helper function qsizetype sizeToInsertAtBegin(const T *const where, qsizetype maxSize) { - Q_ASSERT(size_t(maxSize) <= this->allocatedCapacity() - this->size); + Q_ASSERT(maxSize <= this->allocatedCapacity() - this->size); Q_ASSERT(where >= this->begin() && where <= this->end()); // in range const auto freeAtBegin = this->freeSpaceAtBegin(); @@ -1349,7 +1349,7 @@ public: Q_ASSERT(this->isMutable()); Q_ASSERT(!this->isShared()); Q_ASSERT(newSize > size_t(this->size)); - Q_ASSERT(newSize <= this->allocatedCapacity()); + Q_ASSERT(newSize <= size_t(this->allocatedCapacity())); // Since this is mostly an initialization function, do not follow append // logic of space arrangement. Instead, only prepare as much free space @@ -1366,7 +1366,7 @@ public: Q_ASSERT(this->isMutable() || b == e); Q_ASSERT(!this->isShared() || b == e); Q_ASSERT(b <= e); - Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size); + Q_ASSERT((e - b) <= this->allocatedCapacity() - this->size); if (b == e) // short-cut and handling the case b and e == nullptr return; @@ -1382,7 +1382,7 @@ public: Q_ASSERT(this->isMutable() || b == e); Q_ASSERT(!this->isShared() || b == e); const qsizetype distance = std::distance(b, e); - Q_ASSERT(distance >= 0 && size_t(distance) <= this->allocatedCapacity() - this->size); + Q_ASSERT(distance >= 0 && distance <= this->allocatedCapacity() - this->size); prepareSpaceForAppend(b, e, distance); // ### perf. loss @@ -1398,7 +1398,7 @@ public: Q_ASSERT(this->isMutable() || b == e); Q_ASSERT(!this->isShared() || b == e); Q_ASSERT(b <= e); - Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size); + Q_ASSERT((e - b) <= this->allocatedCapacity() - this->size); if (b == e) // short-cut and handling the case b and e == nullptr return; @@ -1409,7 +1409,7 @@ public: void copyAppend(size_t n, parameter_type t) { Q_ASSERT(!this->isShared() || n == 0); - Q_ASSERT(this->allocatedCapacity() - size_t(this->size) >= n); + Q_ASSERT(size_t(this->allocatedCapacity() - this->size) >= n); // Preserve the value, because it might be a reference to some part of the moved chunk T tmp(t); @@ -1424,7 +1424,7 @@ public: Q_ASSERT(where >= this->begin() && where <= this->end()); Q_ASSERT(b <= e); Q_ASSERT(e <= where || b > this->end() || where == this->end()); // No overlap or append - Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size); + Q_ASSERT((e - b) <= this->allocatedCapacity() - this->size); if (b == e) // short-cut and handling the case b and e == nullptr return; @@ -1451,7 +1451,7 @@ public: { Q_ASSERT(!this->isShared() || (n == 0 && where == this->end())); Q_ASSERT(where >= this->begin() && where <= this->end()); - Q_ASSERT(this->allocatedCapacity() - size_t(this->size) >= n); + Q_ASSERT(size_t(this->allocatedCapacity() - this->size) >= n); if (this->size > 0 && where == this->begin()) { // prepend case - special space arrangement // Preserve the value, because it might be a reference to some part of the moved chunk diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index 7f122b156c..ce5710fa07 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -173,15 +173,15 @@ public: } // forwards from QArrayData - size_t allocatedCapacity() noexcept { return d ? d->allocatedCapacity() : 0; } - size_t constAllocatedCapacity() const noexcept { return d ? d->constAllocatedCapacity() : 0; } + qsizetype allocatedCapacity() noexcept { return d ? d->allocatedCapacity() : 0; } + qsizetype constAllocatedCapacity() const noexcept { return d ? d->constAllocatedCapacity() : 0; } void ref() noexcept { if (d) d->ref(); } bool deref() noexcept { return !d || d->deref(); } bool isMutable() const noexcept { return d; } bool isShared() const noexcept { return !d || d->isShared(); } bool isSharedWith(const QArrayDataPointer &other) const noexcept { return d && d == other.d; } bool needsDetach() const noexcept { return !d || d->needsDetach(); } - size_t detachCapacity(size_t newSize) const noexcept { return d ? d->detachCapacity(newSize) : newSize; } + qsizetype detachCapacity(qsizetype newSize) const noexcept { return d ? d->detachCapacity(newSize) : newSize; } const typename Data::ArrayOptions flags() const noexcept { return d ? typename Data::ArrayOption(d->flags) : Data::DefaultAllocationFlags; } void setFlag(typename Data::ArrayOptions f) noexcept { Q_ASSERT(d); d->flags |= f; } void clearFlag(typename Data::ArrayOptions f) noexcept { Q_ASSERT(d); d->flags &= ~f; } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 80a8d1eec9..185bcc5086 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -545,7 +545,7 @@ inline void QList<T>::remove(qsizetype i, qsizetype n) if (n == 0) return; - const size_t newSize = size() - n; + const auto newSize = size() - n; if (d->needsDetach() || ((d->flags() & Data::CapacityReserved) == 0 && newSize < d->allocatedCapacity()/2)) { @@ -581,8 +581,8 @@ inline void QList<T>::append(const_iterator i1, const_iterator i2) { if (i1 == i2) return; - const size_t distance = std::distance(i1, i2); - const size_t newSize = size() + distance; + const auto distance = std::distance(i1, i2); + const auto newSize = size() + distance; const bool shouldGrow = d->shouldGrowBeforeInsert(d.end(), qsizetype(distance)); if (d->needsDetach() || newSize > d->allocatedCapacity() || shouldGrow) { DataPointer detached(DataPointer::allocateGrow(d, newSize, @@ -604,7 +604,7 @@ inline void QList<T>::append(QList<T> &&other) if (other.d->needsDetach() || !std::is_nothrow_move_constructible_v<T>) return append(other); - const size_t newSize = size() + other.size(); + const auto newSize = size() + other.size(); const bool shouldGrow = d->shouldGrowBeforeInsert(d.end(), other.size()); if (d->needsDetach() || newSize > d->allocatedCapacity() || shouldGrow) { DataPointer detached(DataPointer::allocateGrow(d, newSize, @@ -633,7 +633,7 @@ QList<T>::insert(qsizetype i, qsizetype n, parameter_type t) // we don't have a quick exit for n == 0 // it's not worth wasting CPU cycles for that - const size_t newSize = size() + n; + const auto newSize = size() + n; const bool shouldGrow = d->shouldGrowBeforeInsert(d.begin() + i, n); if (d->needsDetach() || newSize > d->allocatedCapacity() || shouldGrow) { typename Data::ArrayOptions flags = d->detachFlags() | Data::GrowsForward; @@ -666,7 +666,7 @@ QList<T>::emplace(qsizetype i, Args&&... args) Q_ASSERT_X(i >= 0 && i <= d->size, "QList<T>::insert", "index out of range"); const bool shouldGrow = d->shouldGrowBeforeInsert(d.begin() + i, 1); - const size_t newSize = size() + 1; + const auto newSize = size() + 1; if (d->needsDetach() || newSize > d->allocatedCapacity() || shouldGrow) { typename Data::ArrayOptions flags = d->detachFlags() | Data::GrowsForward; if (d.size != 0 && i <= d.size / 4) |