From 7da3a61b5fd5cc726f8fd62691aa5f84c7929800 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20Abecasis?= Date: Mon, 27 Feb 2012 13:52:10 +0100 Subject: [PATCH] Fix signed/unsigned mismatch warnings Introduced by the change of d->alloc to unsigned, in a1621d23. Change-Id: I9e6d7fc2efbf5228c4e59c7128b8c89cf284db24 Reviewed-by: Thiago Macieira Reviewed-by: Kent Hansen --- src/corelib/tools/qvector.h | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 6b41d3d..8c686a2 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -107,7 +107,7 @@ public: d = v.d; } else { d = Data::sharedNull(); - realloc(0, v.d->alloc); + realloc(0, int(v.d->alloc)); qCopy(v.d->begin(), v.d->end(), d->begin()); d->size = v.d->size; d->capacityReserved = v.d->capacityReserved; @@ -133,7 +133,7 @@ public: void resize(int size); - inline int capacity() const { return d->alloc; } + inline int capacity() const { return int(d->alloc); } void reserve(int size); inline void squeeze() { realloc(d->size, d->size); d->capacityReserved = 0; } @@ -339,15 +339,15 @@ private: template void QVector::detach_helper() -{ realloc(d->size, d->alloc); } +{ realloc(d->size, int(d->alloc)); } template void QVector::reserve(int asize) -{ if (asize > d->alloc) realloc(d->size, asize); if (isDetached()) d->capacityReserved = 1; } +{ if (asize > int(d->alloc)) realloc(d->size, asize); if (isDetached()) d->capacityReserved = 1; } template void QVector::resize(int asize) -{ realloc(asize, (asize > d->alloc || (!d->capacityReserved && asize < d->size && asize < (d->alloc >> 1))) ? +{ realloc(asize, (asize > int(d->alloc) || (!d->capacityReserved && asize < d->size && asize < int(d->alloc >> 1))) ? QVectorData::grow(offsetOfTypedData(), asize, sizeof(T)) - : d->alloc); } + : int(d->alloc)); } template inline void QVector::clear() { *this = QVector(); } @@ -414,7 +414,8 @@ QVector::QVector(int asize) { d = malloc(asize); d->ref.initializeOwned(); - d->alloc = d->size = asize; + d->size = asize; + d->alloc = uint(d->size); d->capacityReserved = false; d->offset = offsetOfTypedData(); if (QTypeInfo::isComplex) { @@ -432,7 +433,8 @@ QVector::QVector(int asize, const T &t) { d = malloc(asize); d->ref.initializeOwned(); - d->alloc = d->size = asize; + d->size = asize; + d->alloc = uint(d->size); d->capacityReserved = false; d->offset = offsetOfTypedData(); T* i = d->end(); @@ -446,7 +448,8 @@ QVector::QVector(std::initializer_list args) { d = malloc(int(args.size())); d->ref.initializeOwned(); - d->alloc = d->size = int(args.size()); + d->size = int(args.size()); + d->alloc = uint(d->size); d->capacityReserved = false; d->offset = offsetOfTypedData(); T* i = d->end(); @@ -486,7 +489,7 @@ void QVector::realloc(int asize, int aalloc) } } - if (aalloc != d->alloc || !isDetached()) { + if (aalloc != int(d->alloc) || !isDetached()) { // (re)allocate memory if (QTypeInfo::isStatic) { x = malloc(aalloc); @@ -509,12 +512,12 @@ void QVector::realloc(int asize, int aalloc) x = d = static_cast(mem); x->size = d->size; } QT_CATCH (const std::bad_alloc &) { - if (aalloc > d->alloc) // ignore the error in case we are just shrinking. + if (aalloc > int(d->alloc)) // ignore the error in case we are just shrinking. QT_RETHROW; } } x->ref.initializeOwned(); - x->alloc = aalloc; + x->alloc = uint(aalloc); x->capacityReserved = d->capacityReserved; x->offset = offsetOfTypedData(); } @@ -569,11 +572,11 @@ Q_OUTOFLINE_TEMPLATE T QVector::value(int i, const T &defaultValue) const template void QVector::append(const T &t) { - if (!isDetached() || d->size + 1 > d->alloc) { + if (!isDetached() || d->size + 1 > int(d->alloc)) { const T copy(t); - realloc(d->size, (d->size + 1 > d->alloc) ? + realloc(d->size, (d->size + 1 > int(d->alloc)) ? QVectorData::grow(offsetOfTypedData(), d->size + 1, sizeof(T)) - : d->alloc); + : int(d->alloc)); if (QTypeInfo::isComplex) new (d->end()) T(copy); else @@ -593,7 +596,7 @@ typename QVector::iterator QVector::insert(iterator before, size_type n, c int offset = int(before - d->begin()); if (n != 0) { const T copy(t); - if (!isDetached() || d->size + n > d->alloc) + if (!isDetached() || d->size + n > int(d->alloc)) realloc(d->size, QVectorData::grow(offsetOfTypedData(), d->size + n, sizeof(T))); if (QTypeInfo::isStatic) { T *b = d->end(); -- 2.7.4