From df853fed66d891077ae2d04ecfa171d7e2cd5202 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 19 Jun 2020 20:53:25 +0200 Subject: Use qsizetype in QList The change creates a slight source incompatibility. The main things to take care of are * code using printf statements on list.size(). Using qsizetype in printf statements will always require a cast to work on both 32 and 64 bit. * A few places where overloads now get ambiguous. One example is QRandomGenerator::bounded() that has overloads for int, uint and double, but not int64. * Streaming list.size() to a QDataStream will change the format depending on the architecture. [ChangeLog][QtCore][QList] QList now uses qsizetype to index into elements. Change-Id: Iaff562a4d072b97f458417b670f95971bd47cbc6 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qmetaobjectbuilder.cpp | 4 +- src/corelib/serialization/qjsonobject.cpp | 2 +- src/corelib/text/qstringlist.cpp | 56 +++++++------- src/corelib/text/qstringlist.h | 38 ++++----- src/corelib/tools/qlist.h | 124 +++++++++++++++--------------- 5 files changed, 112 insertions(+), 112 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index b418cd2dab..ba8d92de7d 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -1598,12 +1598,12 @@ void QMetaObjectBuilder::serialize(QDataStream& stream) const stream << QByteArray(); // Write the counts for each type of class member. - stream << d->classInfoNames.size(); + stream << int(d->classInfoNames.size()); stream << int(d->methods.size()); stream << int(d->properties.size()); stream << int(d->enumerators.size()); stream << int(d->constructors.size()); - stream << d->relatedMetaObjects.size(); + stream << int(d->relatedMetaObjects.size()); // Write the items of class information. for (index = 0; index < d->classInfoNames.size(); ++index) { diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index bf2bdb957d..e573485226 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -718,7 +718,7 @@ bool QJsonObject::operator!=(const QJsonObject &other) const QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it) { if (it.o != this || it.i < 0 || it.i >= o->elements.length()) - return {this, o->elements.length()}; + return {this, int(o->elements.length())}; int index = it.i; diff --git a/src/corelib/text/qstringlist.cpp b/src/corelib/text/qstringlist.cpp index 942b1fdf97..6d5228ce6b 100644 --- a/src/corelib/text/qstringlist.cpp +++ b/src/corelib/text/qstringlist.cpp @@ -314,7 +314,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, QStringView s { QStringMatcher matcher(str, cs); QStringList res; - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) if (matcher.indexIn(that->at(i)) != -1) res << that->at(i); return res; @@ -327,7 +327,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QString { QStringMatcher matcher(str, cs); QStringList res; - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) if (matcher.indexIn(that->at(i)) != -1) res << that->at(i); return res; @@ -399,7 +399,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, } /*! - \fn bool QStringList::indexOf(QStringView str, int from) const + \fn bool QStringList::indexOf(QStringView str, qsizetype from) const \overload \since 5.13 @@ -411,7 +411,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, */ /*! - \fn bool QStringList::indexOf(QLatin1String str, int from) const + \fn bool QStringList::indexOf(QLatin1String str, qsizetype from) const \overload \since 5.13 @@ -423,7 +423,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, */ /*! - \fn bool QStringList::lastIndexOf(QStringView str, int from) const + \fn bool QStringList::lastIndexOf(QStringView str, qsizetype from) const \overload \since 5.13 @@ -436,7 +436,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, */ /*! - \fn bool QStringList::lastIndexOf(QLatin1String str, int from) const + \fn bool QStringList::lastIndexOf(QLatin1String str, qsizetype from) const \overload \since 5.13 @@ -460,7 +460,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegularExpression &re) { QStringList res; - for (int i = 0; i < that->size(); ++i) { + for (qsizetype i = 0; i < that->size(); ++i) { if (that->at(i).contains(re)) res << that->at(i); } @@ -506,7 +506,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegula void QtPrivate::QStringList_replaceInStrings(QStringList *that, QStringView before, QStringView after, Qt::CaseSensitivity cs) { - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) (*that)[i].replace(before.data(), before.length(), after.data(), after.length(), cs); } @@ -515,7 +515,7 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, QStringView befo void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, Qt::CaseSensitivity cs) { - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) (*that)[i].replace(before, after, cs); } #endif @@ -546,14 +546,14 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &b */ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegularExpression &re, const QString &after) { - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) (*that)[i].replace(re, after); } #endif // QT_CONFIG(regularexpression) -static int accumulatedSize(const QStringList &list, int seplen) +static qsizetype accumulatedSize(const QStringList &list, qsizetype seplen) { - int result = 0; + qsizetype result = 0; if (!list.isEmpty()) { for (const auto &e : list) result += e.size() + seplen; @@ -579,16 +579,16 @@ static int accumulatedSize(const QStringList &list, int seplen) \since 5.0 \overload join() */ -QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, int seplen) +QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, qsizetype seplen) { - const int totalLength = accumulatedSize(*that, seplen); - const int size = that->size(); + const qsizetype totalLength = accumulatedSize(*that, seplen); + const qsizetype size = that->size(); QString res; if (totalLength == 0) return res; res.reserve(totalLength); - for (int i = 0; i < size; ++i) { + for (qsizetype i = 0; i < size; ++i) { if (i) res.append(sep, seplen); res += that->at(i); @@ -666,7 +666,7 @@ QString QtPrivate::QStringList_join(const QStringList *that, QStringView sep) #if QT_CONFIG(regularexpression) /*! - \fn int QStringList::indexOf(const QRegularExpression &re, int from) const + \fn qsizetype QStringList::indexOf(const QRegularExpression &re, qsizetype from) const \overload \since 5.0 @@ -676,15 +676,15 @@ QString QtPrivate::QStringList_join(const QStringList *that, QStringView sep) \sa lastIndexOf() */ -int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpression &re, int from) +qsizetype QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpression &re, qsizetype from) { if (from < 0) - from = qMax(from + that->size(), 0); + from = qMax(from + that->size(), qsizetype(0)); QString exactPattern = QRegularExpression::anchoredPattern(re.pattern()); QRegularExpression exactRe(exactPattern, re.patternOptions()); - for (int i = from; i < that->size(); ++i) { + for (qsizetype i = from; i < that->size(); ++i) { QRegularExpressionMatch m = exactRe.match(that->at(i)); if (m.hasMatch()) return i; @@ -693,7 +693,7 @@ int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpres } /*! - \fn int QStringList::lastIndexOf(const QRegularExpression &re, int from) const + \fn qsizetype QStringList::lastIndexOf(const QRegularExpression &re, qsizetype from) const \overload \since 5.0 @@ -704,7 +704,7 @@ int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpres \sa indexOf() */ -int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, int from) +qsizetype QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, qsizetype from) { if (from < 0) from += that->size(); @@ -714,7 +714,7 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx QString exactPattern = QRegularExpression::anchoredPattern(re.pattern()); QRegularExpression exactRe(exactPattern, re.patternOptions()); - for (int i = from; i >= 0; --i) { + for (qsizetype i = from; i >= 0; --i) { QRegularExpressionMatch m = exactRe.match(that->at(i)); if (m.hasMatch()) return i; @@ -724,7 +724,7 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx #endif // QT_CONFIG(regularexpression) /*! - \fn int QStringList::removeDuplicates() + \fn qsizetype QStringList::removeDuplicates() \since 4.5 @@ -734,14 +734,14 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx Returns the number of removed entries. */ -int QtPrivate::QStringList_removeDuplicates(QStringList *that) +qsizetype QtPrivate::QStringList_removeDuplicates(QStringList *that) { - int n = that->size(); - int j = 0; + qsizetype n = that->size(); + qsizetype j = 0; QDuplicateTracker seen; seen.reserve(n); - for (int i = 0; i < n; ++i) { + for (qsizetype i = 0; i < n; ++i) { const QString &s = that->at(i); if (seen.hasSeen(s)) continue; diff --git a/src/corelib/text/qstringlist.h b/src/corelib/text/qstringlist.h index 9c4daedd4b..bee76ba67d 100644 --- a/src/corelib/text/qstringlist.h +++ b/src/corelib/text/qstringlist.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -71,7 +71,7 @@ protected: #endif public: inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive); - inline int removeDuplicates(); + inline qsizetype removeDuplicates(); #if QT_STRINGVIEW_LEVEL < 2 inline QString join(const QString &sep) const; @@ -134,15 +134,15 @@ public: inline QStringList &operator<<(const QList &l) { *this += l; return *this; } - inline int indexOf(QStringView str, int from = 0) const; - inline int indexOf(QLatin1String str, int from = 0) const; + inline qsizetype indexOf(QStringView str, qsizetype from = 0) const; + inline qsizetype indexOf(QLatin1String str, qsizetype from = 0) const; - inline int lastIndexOf(QStringView str, int from = -1) const; - inline int lastIndexOf(QLatin1String str, int from = -1) const; + inline qsizetype lastIndexOf(QStringView str, qsizetype from = -1) const; + inline qsizetype lastIndexOf(QLatin1String str, qsizetype from = -1) const; #if QT_CONFIG(regularexpression) - inline int indexOf(const QRegularExpression &re, int from = 0) const; - inline int lastIndexOf(const QRegularExpression &re, int from = -1) const; + inline qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0) const; + inline qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1) const; #endif // QT_CONFIG(regularexpression) using QList::indexOf; @@ -159,9 +159,9 @@ inline const QStringList *QListSpecialMethods::self() const namespace QtPrivate { void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs); - int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); + qsizetype Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); QString Q_CORE_EXPORT QStringList_join(const QStringList *that, QStringView sep); - QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, int seplen); + QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, qsizetype seplen); Q_CORE_EXPORT QString QStringList_join(const QStringList &list, QLatin1String sep); QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, QStringView str, Qt::CaseSensitivity cs); @@ -185,8 +185,8 @@ namespace QtPrivate { #if QT_CONFIG(regularexpression) void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after); QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re); - int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, int from); - int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, int from); + qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, qsizetype from); + qsizetype Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, qsizetype from); #endif // QT_CONFIG(regularexpression) } @@ -195,7 +195,7 @@ inline void QListSpecialMethods::sort(Qt::CaseSensitivity cs) QtPrivate::QStringList_sort(self(), cs); } -inline int QListSpecialMethods::removeDuplicates() +inline qsizetype QListSpecialMethods::removeDuplicates() { return QtPrivate::QStringList_removeDuplicates(self()); } @@ -284,22 +284,22 @@ inline QStringList operator+(const QList &one, const QStringList &other return n; } -inline int QStringList::indexOf(QStringView string, int from) const +inline qsizetype QStringList::indexOf(QStringView string, qsizetype from) const { return QtPrivate::indexOf(*this, string, from); } -inline int QStringList::indexOf(QLatin1String string, int from) const +inline qsizetype QStringList::indexOf(QLatin1String string, qsizetype from) const { return QtPrivate::indexOf(*this, string, from); } -inline int QStringList::lastIndexOf(QStringView string, int from) const +inline qsizetype QStringList::lastIndexOf(QStringView string, qsizetype from) const { return QtPrivate::lastIndexOf(*this, string, from); } -inline int QStringList::lastIndexOf(QLatin1String string, int from) const +inline qsizetype QStringList::lastIndexOf(QLatin1String string, qsizetype from) const { return QtPrivate::lastIndexOf(*this, string, from); } @@ -316,12 +316,12 @@ inline QStringList QListSpecialMethods::filter(const QRegularExpression return QtPrivate::QStringList_filter(self(), rx); } -inline int QStringList::indexOf(const QRegularExpression &rx, int from) const +inline qsizetype QStringList::indexOf(const QRegularExpression &rx, qsizetype from) const { return QtPrivate::QStringList_indexOf(this, rx, from); } -inline int QStringList::lastIndexOf(const QRegularExpression &rx, int from) const +inline qsizetype QStringList::lastIndexOf(const QRegularExpression &rx, qsizetype from) const { return QtPrivate::QStringList_lastIndexOf(this, rx, from); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index c37a2fd97c..6a699aa197 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -54,8 +54,8 @@ QT_BEGIN_NAMESPACE namespace QtPrivate { - template int indexOf(const QList &list, const U &u, int from); - template int lastIndexOf(const QList &list, const U &u, int from); + template qsizetype indexOf(const QList &list, const U &u, qsizetype from); + template qsizetype lastIndexOf(const QList &list, const U &u, qsizetype from); } template struct QListSpecialMethods @@ -79,8 +79,8 @@ class QList DataPointer d; - template friend int QtPrivate::indexOf(const QList &list, const U &u, int from); - template friend int QtPrivate::lastIndexOf(const QList &list, const U &u, int from); + template friend qsizetype QtPrivate::indexOf(const QList &list, const U &u, qsizetype from); + template friend qsizetype QtPrivate::lastIndexOf(const QList &list, const U &u, qsizetype from); public: typedef T Type; @@ -89,7 +89,7 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef int size_type; + typedef qsizetype size_type; typedef qptrdiff difference_type; typedef typename Data::iterator iterator; typedef typename Data::const_iterator const_iterator; @@ -101,7 +101,7 @@ public: using rvalue_ref = typename std::conditional::type; private: - void resize_internal(int i, Qt::Initialization); + void resize_internal(qsizetype i, Qt::Initialization); bool isValidIterator(const_iterator i) const { const std::less less = {}; @@ -115,13 +115,13 @@ public: public: QList() = default; - explicit QList(int size) + explicit QList(qsizetype size) : d(Data::allocate(size)) { if (size) d->appendInitialize(size); } - QList(int size, const T &t) + QList(qsizetype size, const T &t) : d(Data::allocate(size)) { if (size) @@ -177,27 +177,27 @@ public: return !(l == r); } - int size() const noexcept { return int(d->size); } - int count() const noexcept { return size(); } - int length() const noexcept { return size(); } + qsizetype size() const noexcept { return d->size; } + qsizetype count() const noexcept { return size(); } + qsizetype length() const noexcept { return size(); } inline bool isEmpty() const noexcept { return d->size == 0; } - void resize(int size) + void resize(qsizetype size) { resize_internal(size, Qt::Uninitialized); if (size > this->size()) d->appendInitialize(size); } - void resize(int size, parameter_type c) + void resize(qsizetype size, parameter_type c) { resize_internal(size, Qt::Uninitialized); if (size > this->size()) d->copyAppend(size - this->size(), c); } - inline int capacity() const { return int(d->constAllocatedCapacity()); } - void reserve(int size); + inline qsizetype capacity() const { return qsizetype(d->constAllocatedCapacity()); } + void reserve(qsizetype size); inline void squeeze(); void detach() { d.detach(); } @@ -220,18 +220,18 @@ public: } } - const_reference at(int i) const noexcept + const_reference at(qsizetype i) const noexcept { Q_ASSERT_X(size_t(i) < size_t(d->size), "QList::at", "index out of range"); return data()[i]; } - reference operator[](int i) + reference operator[](qsizetype i) { Q_ASSERT_X(size_t(i) < size_t(d->size), "QList::operator[]", "index out of range"); detach(); return data()[i]; } - const_reference operator[](int i) const noexcept { return at(i); } + const_reference operator[](qsizetype i) const noexcept { return at(i); } void append(const_reference t) { append(const_iterator(std::addressof(t)), const_iterator(std::addressof(t)) + 1); } void append(const_iterator i1, const_iterator i2); @@ -243,15 +243,15 @@ public: template reference emplaceBack(Args&&... args) { return *emplace(count(), std::forward(args)...); } - iterator insert(int i, parameter_type t) + iterator insert(qsizetype i, parameter_type t) { return insert(i, 1, t); } - iterator insert(int i, int n, parameter_type t); + iterator insert(qsizetype i, qsizetype n, parameter_type t); iterator insert(const_iterator before, parameter_type t) { Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); return insert(before, 1, t); } - iterator insert(const_iterator before, int n, parameter_type t) + iterator insert(const_iterator before, qsizetype n, parameter_type t) { Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); return insert(std::distance(constBegin(), before), n, t); @@ -261,7 +261,7 @@ public: Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); return insert(std::distance(constBegin(), before), std::move(t)); } - iterator insert(int i, rvalue_ref t) { return emplace(i, std::move(t)); } + iterator insert(qsizetype i, rvalue_ref t) { return emplace(i, std::move(t)); } template iterator emplace(const_iterator before, Args&&... args) @@ -271,72 +271,72 @@ public: } template - iterator emplace(int i, Args&&... args); + iterator emplace(qsizetype i, Args&&... args); #if 0 template< class InputIt > iterator insert( const_iterator pos, InputIt first, InputIt last ); iterator insert( const_iterator pos, std::initializer_list ilist ); #endif - void replace(int i, const T &t) + void replace(qsizetype i, const T &t) { Q_ASSERT_X(i >= 0 && i < d->size, "QList::replace", "index out of range"); const T copy(t); data()[i] = copy; } - void replace(int i, rvalue_ref t) + void replace(qsizetype i, rvalue_ref t) { Q_ASSERT_X(i >= 0 && i < d->size, "QList::replace", "index out of range"); const T copy(std::move(t)); data()[i] = std::move(copy); } - void remove(int i, int n = 1); + void remove(qsizetype i, qsizetype n = 1); void removeFirst() { Q_ASSERT(!isEmpty()); remove(0); } void removeLast() { Q_ASSERT(!isEmpty()); remove(size() - 1); } value_type takeFirst() { Q_ASSERT(!isEmpty()); value_type v = std::move(first()); remove(0); return v; } value_type takeLast() { Q_ASSERT(!isEmpty()); value_type v = std::move(last()); remove(size() - 1); return v; } - QList &fill(parameter_type t, int size = -1); + QList &fill(parameter_type t, qsizetype size = -1); - int indexOf(const T &t, int from = 0) const noexcept; - int lastIndexOf(const T &t, int from = -1) const noexcept; + qsizetype indexOf(const T &t, qsizetype from = 0) const noexcept; + qsizetype lastIndexOf(const T &t, qsizetype from = -1) const noexcept; bool contains(const T &t) const noexcept { return indexOf(t) != -1; } - int count(const T &t) const noexcept + qsizetype count(const T &t) const noexcept { - return int(std::count(&*cbegin(), &*cend(), t)); + return qsizetype(std::count(&*cbegin(), &*cend(), t)); } // QList compatibility - void removeAt(int i) { remove(i); } - int removeAll(const T &t) + void removeAt(qsizetype i) { remove(i); } + qsizetype removeAll(const T &t) { const const_iterator ce = this->cend(), cit = std::find(this->cbegin(), ce, t); if (cit == ce) return 0; - int index = cit - this->cbegin(); + qsizetype index = cit - this->cbegin(); // next operation detaches, so ce, cit, t may become invalidated: const T tCopy = t; const iterator e = end(), it = std::remove(begin() + index, e, tCopy); - const int result = std::distance(it, e); + const qsizetype result = std::distance(it, e); erase(it, e); return result; } bool removeOne(const T &t) { - const int i = indexOf(t); + const qsizetype i = indexOf(t); if (i < 0) return false; remove(i); return true; } - T takeAt(int i) { T t = std::move((*this)[i]); remove(i); return t; } - void move(int from, int to) + T takeAt(qsizetype i) { T t = std::move((*this)[i]); remove(i); return t; } + void move(qsizetype from, qsizetype to) { - Q_ASSERT_X(from >= 0 && from < size(), "QList::move(int,int)", "'from' is out-of-range"); - Q_ASSERT_X(to >= 0 && to < size(), "QList::move(int,int)", "'to' is out-of-range"); + Q_ASSERT_X(from >= 0 && from < size(), "QList::move(qsizetype, qsizetype)", "'from' is out-of-range"); + Q_ASSERT_X(to >= 0 && to < size(), "QList::move(qsizetype, qsizetype)", "'to' is out-of-range"); if (from == to) // don't detach when no-op return; detach(); @@ -376,12 +376,12 @@ public: inline const T &constLast() const { Q_ASSERT(!isEmpty()); return *(end()-1); } inline bool startsWith(const T &t) const { return !isEmpty() && first() == t; } inline bool endsWith(const T &t) const { return !isEmpty() && last() == t; } - QList mid(int pos, int len = -1) const; + QList mid(qsizetype pos, qsizetype len = -1) const; - T value(int i) const { return value(i, T()); } - T value(int i, const T &defaultValue) const; + T value(qsizetype i) const { return value(i, T()); } + T value(qsizetype i, const T &defaultValue) const; - void swapItemsAt(int i, int j) { + void swapItemsAt(qsizetype i, qsizetype j) { Q_ASSERT_X(i >= 0 && i < size() && j >= 0 && j < size(), "QList::swap", "index out of range"); detach(); @@ -429,7 +429,7 @@ public: static inline QList fromVector(const QList &vector) { return vector; } inline QList toVector() const { return *this; } - template + template static QList fromReadOnlyData(const T (&t)[N]) { return QList({ nullptr, const_cast(t), N }); @@ -444,7 +444,7 @@ QList(InputIterator, InputIterator) -> QList; #endif template -inline void QList::resize_internal(int newSize, Qt::Initialization) +inline void QList::resize_internal(qsizetype newSize, Qt::Initialization) { Q_ASSERT(newSize >= 0); @@ -463,7 +463,7 @@ inline void QList::resize_internal(int newSize, Qt::Initialization) } template -void QList::reserve(int asize) +void QList::reserve(qsizetype asize) { // capacity() == 0 for immutable data, so this will force a detaching below if (asize <= capacity()) { @@ -496,7 +496,7 @@ inline void QList::squeeze() } template -inline void QList::remove(int i, int n) +inline void QList::remove(qsizetype i, qsizetype n) { Q_ASSERT_X(size_t(i) + size_t(n) <= size_t(d->size), "QList::remove", "index out of range"); Q_ASSERT_X(n >= 0, "QList::remove", "invalid count"); @@ -531,7 +531,7 @@ void QList::prepend(rvalue_ref t) { insert(0, std::move(t)); } template -inline T QList::value(int i, const T &defaultValue) const +inline T QList::value(qsizetype i, const T &defaultValue) const { return size_t(i) < size_t(d->size) ? at(i) : defaultValue; } @@ -556,7 +556,7 @@ inline void QList::append(const_iterator i1, const_iterator i2) template inline typename QList::iterator -QList::insert(int i, int n, parameter_type t) +QList::insert(qsizetype i, qsizetype n, parameter_type t) { Q_ASSERT_X(size_t(i) <= size_t(d->size), "QList::insert", "index out of range"); @@ -590,7 +590,7 @@ QList::insert(int i, int n, parameter_type t) template template typename QList::iterator -QList::emplace(int i, Args&&... args) +QList::emplace(qsizetype i, Args&&... args) { Q_ASSERT_X(i >= 0 && i <= d->size, "QList::insert", "index out of range"); @@ -631,15 +631,15 @@ typename QList::iterator QList::erase(const_iterator abegin, const_iterato Q_ASSERT_X(isValidIterator(aend), "QList::erase", "The specified iterator argument 'aend' is invalid"); Q_ASSERT(aend >= abegin); - int i = std::distance(d.constBegin(), abegin); - int n = std::distance(abegin, aend); + qsizetype i = std::distance(d.constBegin(), abegin); + qsizetype n = std::distance(abegin, aend); remove(i, n); return d.begin() + i; } template -inline QList &QList::fill(parameter_type t, int newSize) +inline QList &QList::fill(parameter_type t, qsizetype newSize) { if (newSize == -1) newSize = size(); @@ -661,22 +661,22 @@ inline QList &QList::fill(parameter_type t, int newSize) namespace QtPrivate { template -int indexOf(const QList &vector, const U &u, int from) +qsizetype indexOf(const QList &vector, const U &u, qsizetype from) { if (from < 0) - from = qMax(from + vector.size(), 0); + from = qMax(from + vector.size(), qsizetype(0)); if (from < vector.size()) { auto n = vector.begin() + from - 1; auto e = vector.end(); while (++n != e) if (*n == u) - return int(n - vector.begin()); + return qsizetype(n - vector.begin()); } return -1; } template -int lastIndexOf(const QList &vector, const U &u, int from) +qsizetype lastIndexOf(const QList &vector, const U &u, qsizetype from) { if (from < 0) from += vector.d->size; @@ -687,7 +687,7 @@ int lastIndexOf(const QList &vector, const U &u, int from) auto n = vector.begin() + from + 1; while (n != b) { if (*--n == u) - return int(n - b); + return qsizetype(n - b); } } return -1; @@ -695,19 +695,19 @@ int lastIndexOf(const QList &vector, const U &u, int from) } template -int QList::indexOf(const T &t, int from) const noexcept +qsizetype QList::indexOf(const T &t, qsizetype from) const noexcept { return QtPrivate::indexOf(*this, t, from); } template -int QList::lastIndexOf(const T &t, int from) const noexcept +qsizetype QList::lastIndexOf(const T &t, qsizetype from) const noexcept { return QtPrivate::lastIndexOf(*this, t, from); } template -inline QList QList::mid(int pos, int len) const +inline QList QList::mid(qsizetype pos, qsizetype len) const { qsizetype p = pos; qsizetype l = len; -- cgit v1.2.3