summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2020-08-05 15:53:48 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2020-08-18 04:06:04 +0200
commitaf5e8c2e97cef39d0b8d21fe072e24598d48871b (patch)
tree1db61e6c7079ae7b6c17d2e434b8b2c8b5e774ea /src/corelib/serialization
parent1fc7ca091b3fdda52381a383318a3a752ec21132 (diff)
Use qsizetype for size in QJsonArray and QJsonObject
Change-Id: I126b7e817f076486910777bb4e3354487ad670cd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r--src/corelib/serialization/qjson_p.h6
-rw-r--r--src/corelib/serialization/qjsonarray.cpp54
-rw-r--r--src/corelib/serialization/qjsonarray.h60
-rw-r--r--src/corelib/serialization/qjsondocument.cpp2
-rw-r--r--src/corelib/serialization/qjsondocument.h2
-rw-r--r--src/corelib/serialization/qjsonobject.cpp74
-rw-r--r--src/corelib/serialization/qjsonobject.h56
-rw-r--r--src/corelib/serialization/qjsonvalue.cpp4
-rw-r--r--src/corelib/serialization/qjsonvalue.h15
9 files changed, 140 insertions, 133 deletions
diff --git a/src/corelib/serialization/qjson_p.h b/src/corelib/serialization/qjson_p.h
index b6f01bff1c..90f1071b71 100644
--- a/src/corelib/serialization/qjson_p.h
+++ b/src/corelib/serialization/qjson_p.h
@@ -129,7 +129,7 @@ struct ObjectIterator
ObjectIterator &operator-=(difference_type n) { it -= 2 * n; return *this; }
reference operator*() const { return *it; }
- reference operator[](int n) const { return it[n * 2]; }
+ reference operator[](qsizetype n) const { return it[n * 2]; }
bool operator<(ObjectIterator other) const { return it < other.it; }
bool operator>(ObjectIterator other) const { return it > other.it; }
@@ -149,7 +149,7 @@ inline ObjectIterator<Element, ElementsIterator> operator+(
}
template<typename Element, typename ElementsIterator>
inline ObjectIterator<Element, ElementsIterator> operator+(
- int n, ObjectIterator<Element, ElementsIterator> a)
+ qsizetype n, ObjectIterator<Element, ElementsIterator> a)
{
return {a.elementsIterator() + 2 * n};
}
@@ -161,7 +161,7 @@ inline ObjectIterator<Element, ElementsIterator> operator-(
return {a.elementsIterator() - 2 * n};
}
template<typename Element, typename ElementsIterator>
-inline int operator-(
+inline qsizetype operator-(
ObjectIterator<Element, ElementsIterator> a,
ObjectIterator<Element, ElementsIterator> b)
{
diff --git a/src/corelib/serialization/qjsonarray.cpp b/src/corelib/serialization/qjsonarray.cpp
index 7e29bdea3f..bf678a0bd8 100644
--- a/src/corelib/serialization/qjsonarray.cpp
+++ b/src/corelib/serialization/qjsonarray.cpp
@@ -93,7 +93,7 @@ QT_BEGIN_NAMESPACE
/*!
\typedef QJsonArray::size_type
- Typedef for int. Provided for STL compatibility.
+ Typedef for qsizetype. Provided for STL compatibility.
*/
/*!
@@ -105,7 +105,7 @@ QT_BEGIN_NAMESPACE
/*!
\typedef QJsonArray::difference_type
- Typedef for int. Provided for STL compatibility.
+ Typedef for qsizetype. Provided for STL compatibility.
*/
/*!
@@ -285,7 +285,7 @@ QVariantList QJsonArray::toVariantList() const
/*!
Returns the number of values stored in the array.
*/
-int QJsonArray::size() const
+qsizetype QJsonArray::size() const
{
return a ? a->elements.size() : 0;
}
@@ -314,7 +314,7 @@ bool QJsonArray::isEmpty() const
The returned QJsonValue is \c Undefined, if \a i is out of bounds.
*/
-QJsonValue QJsonArray::at(int i) const
+QJsonValue QJsonArray::at(qsizetype i) const
{
if (!a || i < 0 || i >= a->elements.size())
return QJsonValue(QJsonValue::Undefined);
@@ -374,7 +374,7 @@ void QJsonArray::append(const QJsonValue &value)
\sa insert(), replace()
*/
-void QJsonArray::removeAt(int i)
+void QJsonArray::removeAt(qsizetype i)
{
if (!a || i < 0 || i >= a->elements.length())
return;
@@ -410,7 +410,7 @@ void QJsonArray::removeAt(int i)
\sa removeAt()
*/
-QJsonValue QJsonArray::takeAt(int i)
+QJsonValue QJsonArray::takeAt(qsizetype i)
{
if (!a || i < 0 || i >= a->elements.length())
return QJsonValue(QJsonValue::Undefined);
@@ -428,7 +428,7 @@ QJsonValue QJsonArray::takeAt(int i)
\sa append(), prepend(), replace(), removeAt()
*/
-void QJsonArray::insert(int i, const QJsonValue &value)
+void QJsonArray::insert(qsizetype i, const QJsonValue &value)
{
if (a)
detach(a->elements.length() + 1);
@@ -464,7 +464,7 @@ void QJsonArray::insert(int i, const QJsonValue &value)
\sa operator[](), removeAt()
*/
-void QJsonArray::replace(int i, const QJsonValue &value)
+void QJsonArray::replace(qsizetype i, const QJsonValue &value)
{
Q_ASSERT (a && i >= 0 && i < a->elements.length());
detach();
@@ -478,7 +478,7 @@ void QJsonArray::replace(int i, const QJsonValue &value)
*/
bool QJsonArray::contains(const QJsonValue &value) const
{
- for (int i = 0; i < size(); i++) {
+ for (qsizetype i = 0; i < size(); i++) {
if (at(i) == value)
return true;
}
@@ -498,7 +498,7 @@ bool QJsonArray::contains(const QJsonValue &value) const
\sa at()
*/
-QJsonValueRef QJsonArray::operator [](int i)
+QJsonValueRef QJsonArray::operator [](qsizetype i)
{
Q_ASSERT(a && i >= 0 && i < a->elements.length());
return QJsonValueRef(this, i);
@@ -509,7 +509,7 @@ QJsonValueRef QJsonArray::operator [](int i)
Same as at().
*/
-QJsonValue QJsonArray::operator[](int i) const
+QJsonValue QJsonArray::operator[](qsizetype i) const
{
return at(i);
}
@@ -529,7 +529,7 @@ bool QJsonArray::operator==(const QJsonArray &other) const
if (a->elements.length() != other.a->elements.length())
return false;
- for (int i = 0; i < a->elements.length(); ++i) {
+ for (qsizetype i = 0; i < a->elements.length(); ++i) {
if (a->valueAt(i) != other.a->valueAt(i))
return false;
}
@@ -700,7 +700,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa QJsonArray::begin(), QJsonArray::end()
*/
-/*! \fn QJsonArray::iterator::iterator(QJsonArray *array, int index)
+/*! \fn QJsonArray::iterator::iterator(QJsonArray *array, qsizetype index)
\internal
*/
@@ -724,7 +724,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
Returns a pointer to a modifiable reference to the current item.
*/
-/*! \fn QJsonValueRef QJsonArray::iterator::operator[](int j) const
+/*! \fn QJsonValueRef QJsonArray::iterator::operator[](qsizetype j) const
Returns a modifiable reference to the item at offset \a j from the
item pointed to by this iterator (the item at position \c{*this + j}).
@@ -831,7 +831,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
current and returns an iterator to the previously current item.
*/
-/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator+=(int j)
+/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator+=(qsizetype j)
Advances the iterator by \a j items. If \a j is negative, the
iterator goes backward.
@@ -839,7 +839,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa operator-=(), operator+()
*/
-/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator-=(int j)
+/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator-=(qsizetype j)
Makes the iterator go back by \a j items. If \a j is negative,
the iterator goes forward.
@@ -847,7 +847,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa operator+=(), operator-()
*/
-/*! \fn QJsonArray::iterator QJsonArray::iterator::operator+(int j) const
+/*! \fn QJsonArray::iterator QJsonArray::iterator::operator+(qsizetype j) const
Returns an iterator to the item at \a j positions forward from
this iterator. If \a j is negative, the iterator goes backward.
@@ -855,7 +855,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa operator-(), operator+=()
*/
-/*! \fn QJsonArray::iterator QJsonArray::iterator::operator-(int j) const
+/*! \fn QJsonArray::iterator QJsonArray::iterator::operator-(qsizetype j) const
Returns an iterator to the item at \a j positions backward from
this iterator. If \a j is negative, the iterator goes forward.
@@ -863,7 +863,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa operator+(), operator-=()
*/
-/*! \fn int QJsonArray::iterator::operator-(iterator other) const
+/*! \fn qsizetype QJsonArray::iterator::operator-(iterator other) const
Returns the number of items between the item pointed to by \a
other and the item pointed to by this iterator.
@@ -909,7 +909,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa QJsonArray::constBegin(), QJsonArray::constEnd()
*/
-/*! \fn QJsonArray::const_iterator::const_iterator(const QJsonArray *array, int index)
+/*! \fn QJsonArray::const_iterator::const_iterator(const QJsonArray *array, qsizetype index)
\internal
*/
@@ -954,7 +954,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
Returns a pointer to the current item.
*/
-/*! \fn QJsonValue QJsonArray::const_iterator::operator[](int j) const
+/*! \fn QJsonValue QJsonArray::const_iterator::operator[](qsizetype j) const
Returns the item at offset \a j from the item pointed to by this iterator (the item at
position \c{*this + j}).
@@ -1047,7 +1047,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
current and returns an iterator to the previously current item.
*/
-/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator+=(int j)
+/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator+=(qsizetype j)
Advances the iterator by \a j items. If \a j is negative, the
iterator goes backward.
@@ -1055,7 +1055,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa operator-=(), operator+()
*/
-/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator-=(int j)
+/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator-=(qsizetype j)
Makes the iterator go back by \a j items. If \a j is negative,
the iterator goes forward.
@@ -1063,7 +1063,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa operator+=(), operator-()
*/
-/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator+(int j) const
+/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator+(qsizetype j) const
Returns an iterator to the item at \a j positions forward from
this iterator. If \a j is negative, the iterator goes backward.
@@ -1071,7 +1071,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa operator-(), operator+=()
*/
-/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator-(int j) const
+/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator-(qsizetype j) const
Returns an iterator to the item at \a j positions backward from
this iterator. If \a j is negative, the iterator goes forward.
@@ -1079,7 +1079,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
\sa operator+(), operator-=()
*/
-/*! \fn int QJsonArray::const_iterator::operator-(const_iterator other) const
+/*! \fn qsizetype QJsonArray::const_iterator::operator-(const_iterator other) const
Returns the number of items between the item pointed to by \a
other and the item pointed to by this iterator.
@@ -1088,7 +1088,7 @@ bool QJsonArray::operator!=(const QJsonArray &other) const
/*!
\internal
*/
-bool QJsonArray::detach(uint reserve)
+bool QJsonArray::detach(qsizetype reserve)
{
if (!a)
return true;
diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h
index 4202322be6..b39e85a726 100644
--- a/src/corelib/serialization/qjsonarray.h
+++ b/src/corelib/serialization/qjsonarray.h
@@ -75,27 +75,27 @@ public:
static QJsonArray fromVariantList(const QVariantList &list);
QVariantList toVariantList() const;
- int size() const;
- inline int count() const { return size(); }
+ qsizetype size() const;
+ inline qsizetype count() const { return size(); }
bool isEmpty() const;
- QJsonValue at(int i) const;
+ QJsonValue at(qsizetype i) const;
QJsonValue first() const;
QJsonValue last() const;
void prepend(const QJsonValue &value);
void append(const QJsonValue &value);
- void removeAt(int i);
- QJsonValue takeAt(int i);
+ void removeAt(qsizetype i);
+ QJsonValue takeAt(qsizetype i);
inline void removeFirst() { removeAt(0); }
inline void removeLast() { removeAt(size() - 1); }
- void insert(int i, const QJsonValue &value);
- void replace(int i, const QJsonValue &value);
+ void insert(qsizetype i, const QJsonValue &value);
+ void replace(qsizetype i, const QJsonValue &value);
bool contains(const QJsonValue &element) const;
- QJsonValueRef operator[](int i);
- QJsonValue operator[](int i) const;
+ QJsonValueRef operator[](qsizetype i);
+ QJsonValue operator[](qsizetype i) const;
bool operator==(const QJsonArray &other) const;
bool operator!=(const QJsonArray &other) const;
@@ -110,13 +110,13 @@ public:
class iterator {
public:
typedef std::random_access_iterator_tag iterator_category;
- typedef int difference_type;
+ typedef qsizetype difference_type;
typedef QJsonValue value_type;
typedef QJsonValueRef reference;
typedef QJsonValueRef *pointer;
inline iterator() : item(static_cast<QJsonArray *>(nullptr), 0) { }
- explicit inline iterator(QJsonArray *array, int index) : item(array, index) { }
+ explicit inline iterator(QJsonArray *array, qsizetype index) : item(array, index) { }
constexpr iterator(const iterator &other) = default;
iterator &operator=(const iterator &other)
@@ -128,7 +128,8 @@ public:
inline QJsonValueRef operator*() const { return item; }
inline QJsonValueRef *operator->() const { return &item; }
- inline QJsonValueRef operator[](int j) const { return { item.a, int(item.index) + j }; }
+ inline QJsonValueRef operator[](qsizetype j) const
+ { return { item.a, qsizetype(item.index) + j }; }
inline bool operator==(const iterator &o) const
{ return item.a == o.item.a && item.index == o.item.index; }
@@ -152,11 +153,13 @@ public:
inline iterator operator++(int) { iterator n = *this; ++item.index; return n; }
inline iterator &operator--() { item.index--; return *this; }
inline iterator operator--(int) { iterator n = *this; item.index--; return n; }
- inline iterator &operator+=(int j) { item.index += j; return *this; }
- inline iterator &operator-=(int j) { item.index -= j; return *this; }
- inline iterator operator+(int j) const { return iterator(item.a, item.index + j); }
- inline iterator operator-(int j) const { return iterator(item.a, item.index - j); }
- inline int operator-(iterator j) const { return item.index - j.item.index; }
+ inline iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
+ inline iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
+ inline iterator operator+(qsizetype j) const
+ { return iterator(item.a, qsizetype(item.index) + j); }
+ inline iterator operator-(qsizetype j) const
+ { return iterator(item.a, qsizetype(item.index) - j); }
+ inline qsizetype operator-(iterator j) const { return item.index - j.item.index; }
private:
mutable QJsonValueRef item;
@@ -173,7 +176,7 @@ public:
typedef const QJsonValueRef *pointer;
inline const_iterator() : item(static_cast<QJsonArray *>(nullptr), 0) { }
- explicit inline const_iterator(const QJsonArray *array, int index)
+ explicit inline const_iterator(const QJsonArray *array, qsizetype index)
: item(const_cast<QJsonArray *>(array), index) { }
inline const_iterator(const iterator &o) : item(o.item) { }
@@ -188,7 +191,8 @@ public:
inline const QJsonValueRef operator*() const { return item; }
inline const QJsonValueRef *operator->() const { return &item; }
- inline QJsonValueRef operator[](int j) const { return { item.a, int(item.index) + j }; }
+ inline QJsonValueRef operator[](qsizetype j) const
+ { return { item.a, qsizetype(item.index) + j }; }
inline bool operator==(const const_iterator &o) const
{ return item.a == o.item.a && item.index == o.item.index; }
inline bool operator!=(const const_iterator &o) const { return !(*this == o); }
@@ -202,11 +206,13 @@ public:
inline const_iterator operator++(int) { const_iterator n = *this; ++item.index; return n; }
inline const_iterator &operator--() { item.index--; return *this; }
inline const_iterator operator--(int) { const_iterator n = *this; item.index--; return n; }
- inline const_iterator &operator+=(int j) { item.index += j; return *this; }
- inline const_iterator &operator-=(int j) { item.index -= j; return *this; }
- inline const_iterator operator+(int j) const { return const_iterator(item.a, item.index + j); }
- inline const_iterator operator-(int j) const { return const_iterator(item.a, item.index - j); }
- inline int operator-(const_iterator j) const { return item.index - j.item.index; }
+ inline const_iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
+ inline const_iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
+ inline const_iterator operator+(qsizetype j) const
+ { return const_iterator(item.a, qsizetype(item.index) + j); }
+ inline const_iterator operator-(qsizetype j) const
+ { return const_iterator(item.a, qsizetype(item.index) - j); }
+ inline qsizetype operator-(const_iterator j) const { return item.index - j.item.index; }
private:
QJsonValueRef item;
@@ -246,13 +252,13 @@ public:
inline void pop_front() { removeFirst(); }
inline void pop_back() { removeLast(); }
inline bool empty() const { return isEmpty(); }
- typedef int size_type;
+ typedef qsizetype size_type;
typedef QJsonValue value_type;
typedef value_type *pointer;
typedef const value_type *const_pointer;
typedef QJsonValueRef reference;
typedef QJsonValue const_reference;
- typedef int difference_type;
+ typedef qsizetype difference_type;
private:
friend class QJsonValue;
@@ -261,7 +267,7 @@ private:
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &);
QJsonArray(QCborContainerPrivate *array);
- bool detach(uint reserve = 0);
+ bool detach(qsizetype reserve = 0);
QExplicitlySharedDataPointer<QCborContainerPrivate> a;
};
diff --git a/src/corelib/serialization/qjsondocument.cpp b/src/corelib/serialization/qjsondocument.cpp
index 6ec169da62..f06867341c 100644
--- a/src/corelib/serialization/qjsondocument.cpp
+++ b/src/corelib/serialization/qjsondocument.cpp
@@ -482,7 +482,7 @@ const QJsonValue QJsonDocument::operator[](QLatin1String key) const
\sa QJsonValue, QJsonValue::isUndefined(), QJsonArray
*/
-const QJsonValue QJsonDocument::operator[](int i) const
+const QJsonValue QJsonDocument::operator[](qsizetype i) const
{
if (!isArray())
return QJsonValue(QJsonValue::Undefined);
diff --git a/src/corelib/serialization/qjsondocument.h b/src/corelib/serialization/qjsondocument.h
index ea190679bd..d262a5e6b6 100644
--- a/src/corelib/serialization/qjsondocument.h
+++ b/src/corelib/serialization/qjsondocument.h
@@ -135,7 +135,7 @@ public:
#endif
const QJsonValue operator[](QStringView key) const;
const QJsonValue operator[](QLatin1String key) const;
- const QJsonValue operator[](int i) const;
+ const QJsonValue operator[](qsizetype i) const;
bool operator==(const QJsonDocument &other) const;
bool operator!=(const QJsonDocument &other) const { return !(*this == other); }
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp
index 419021a798..0c4af59163 100644
--- a/src/corelib/serialization/qjsonobject.cpp
+++ b/src/corelib/serialization/qjsonobject.cpp
@@ -106,7 +106,7 @@ QT_BEGIN_NAMESPACE
/*!
\typedef QJsonObject::size_type
- Typedef for int. Provided for STL compatibility.
+ Typedef for qsizetype. Provided for STL compatibility.
*/
@@ -272,7 +272,7 @@ QStringList QJsonObject::keys() const
QStringList keys;
if (o) {
keys.reserve(o->elements.length() / 2);
- for (int i = 0, end = o->elements.length(); i < end; i += 2)
+ for (qsizetype i = 0, end = o->elements.length(); i < end; i += 2)
keys.append(o->stringAt(i));
}
return keys;
@@ -281,7 +281,7 @@ QStringList QJsonObject::keys() const
/*!
Returns the number of (key, value) pairs stored in the object.
*/
-int QJsonObject::size() const
+qsizetype QJsonObject::size() const
{
return o ? o->elements.length() / 2 : 0;
}
@@ -297,8 +297,8 @@ bool QJsonObject::isEmpty() const
}
template<typename String>
-static int indexOf(const QExplicitlySharedDataPointer<QCborContainerPrivate> &o,
- String key, bool *keyExists)
+static qsizetype indexOf(const QExplicitlySharedDataPointer<QCborContainerPrivate> &o,
+ String key, bool *keyExists)
{
const auto begin = QJsonPrivate::ConstKeyIterator(o->elements.constBegin());
const auto end = QJsonPrivate::ConstKeyIterator(o->elements.constEnd());
@@ -355,7 +355,7 @@ QJsonValue QJsonObject::valueImpl(T key) const
return QJsonValue(QJsonValue::Undefined);
bool keyExists;
- int i = indexOf(o, key, &keyExists);
+ auto i = indexOf(o, key, &keyExists);
if (!keyExists)
return QJsonValue(QJsonValue::Undefined);
return QJsonPrivate::Value::fromTrustedCbor(o->valueAt(i + 1));
@@ -439,7 +439,7 @@ QJsonValueRef QJsonObject::atImpl(T key)
o = new QCborContainerPrivate;
bool keyExists = false;
- int index = indexOf(o, key, &keyExists);
+ auto index = indexOf(o, key, &keyExists);
if (!keyExists) {
detach(o->elements.length() / 2 + 1);
o->insertAt(index, key);
@@ -498,7 +498,7 @@ QJsonObject::iterator QJsonObject::insertImpl(T key, const QJsonValue &value)
return end();
}
bool keyExists = false;
- int pos = o ? indexOf(o, key, &keyExists) : 0;
+ auto pos = o ? indexOf(o, key, &keyExists) : 0;
return insertAt(pos, key, value, keyExists);
}
@@ -506,7 +506,7 @@ QJsonObject::iterator QJsonObject::insertImpl(T key, const QJsonValue &value)
\internal
*/
template <typename T>
-QJsonObject::iterator QJsonObject::insertAt(int pos, T key, const QJsonValue &value, bool keyExists)
+QJsonObject::iterator QJsonObject::insertAt(qsizetype pos, T key, const QJsonValue &value, bool keyExists)
{
if (o)
detach(o->elements.length() / 2 + (keyExists ? 0 : 1));
@@ -562,7 +562,7 @@ void QJsonObject::removeImpl(T key)
return;
bool keyExists;
- int index = indexOf(o, key, &keyExists);
+ auto index = indexOf(o, key, &keyExists);
if (!keyExists)
return;
@@ -613,7 +613,7 @@ QJsonValue QJsonObject::takeImpl(T key)
return QJsonValue(QJsonValue::Undefined);
bool keyExists;
- int index = indexOf(o, key, &keyExists);
+ auto index = indexOf(o, key, &keyExists);
if (!keyExists)
return QJsonValue(QJsonValue::Undefined);
@@ -681,7 +681,7 @@ bool QJsonObject::operator==(const QJsonObject &other) const
if (o->elements.length() != other.o->elements.length())
return false;
- for (int i = 0, end = o->elements.length(); i < end; ++i) {
+ for (qsizetype i = 0, end = o->elements.length(); i < end; ++i) {
if (o->valueAt(i) != other.o->valueAt(i))
return false;
}
@@ -706,8 +706,8 @@ bool QJsonObject::operator!=(const QJsonObject &other) const
*/
QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it)
{
- if (it.item.o != this || it.item.index < 0 || it.item.index >= o->elements.length())
- return {this, int(o->elements.length())};
+ if (it.item.o != this || qsizetype(it.item.index) >= o->elements.length())
+ return {this, o->elements.length()};
removeAt(it.item.index);
@@ -754,7 +754,7 @@ template <typename T>
QJsonObject::iterator QJsonObject::findImpl(T key)
{
bool keyExists = false;
- int index = o ? indexOf(o, key, &keyExists) : 0;
+ auto index = o ? indexOf(o, key, &keyExists) : 0;
if (!keyExists)
return end();
detach();
@@ -819,20 +819,20 @@ template <typename T>
QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
{
bool keyExists = false;
- int index = o ? indexOf(o, key, &keyExists) : 0;
+ auto index = o ? indexOf(o, key, &keyExists) : 0;
if (!keyExists)
return end();
return {this, index / 2};
}
-/*! \fn int QJsonObject::count() const
+/*! \fn qsizetype QJsonObject::count() const
\overload
Same as size().
*/
-/*! \fn int QJsonObject::length() const
+/*! \fn qsizetype QJsonObject::length() const
\overload
@@ -956,7 +956,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa QJsonObject::begin(), QJsonObject::end()
*/
-/*! \fn QJsonObject::iterator::iterator(QJsonObject *obj, int index)
+/*! \fn QJsonObject::iterator::iterator(QJsonObject *obj, qsizetype index)
\internal
*/
@@ -1007,7 +1007,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
Returns a pointer to a modifiable reference to the current item.
*/
-/*! \fn const QJsonValueRef QJsonObject::iterator::operator[](int j)
+/*! \fn const QJsonValueRef QJsonObject::iterator::operator[](qsizetype j)
Returns a modifiable reference to the item at offset \a j from the
item pointed to by this iterator (the item at position \c{*this + j}).
@@ -1116,7 +1116,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
current item.
*/
-/*! \fn QJsonObject::iterator QJsonObject::iterator::operator+(int j) const
+/*! \fn QJsonObject::iterator QJsonObject::iterator::operator+(qsizetype j) const
Returns an iterator to the item at \a j positions forward from
this iterator. If \a j is negative, the iterator goes backward.
@@ -1125,7 +1125,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
*/
-/*! \fn QJsonObject::iterator QJsonObject::iterator::operator-(int j) const
+/*! \fn QJsonObject::iterator QJsonObject::iterator::operator-(qsizetype j) const
Returns an iterator to the item at \a j positions backward from
this iterator. If \a j is negative, the iterator goes forward.
@@ -1133,7 +1133,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator+()
*/
-/*! \fn QJsonObject::iterator &QJsonObject::iterator::operator+=(int j)
+/*! \fn QJsonObject::iterator &QJsonObject::iterator::operator+=(qsizetype j)
Advances the iterator by \a j items. If \a j is negative, the
iterator goes backward.
@@ -1141,7 +1141,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator-=(), operator+()
*/
-/*! \fn QJsonObject::iterator &QJsonObject::iterator::operator-=(int j)
+/*! \fn QJsonObject::iterator &QJsonObject::iterator::operator-=(qsizetype j)
Makes the iterator go back by \a j items. If \a j is negative,
the iterator goes forward.
@@ -1149,7 +1149,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator+=(), operator-()
*/
-/*! \fn int QJsonObject::iterator::operator-(iterator other) const
+/*! \fn qsizetype QJsonObject::iterator::operator-(iterator other) const
Returns the number of items between the item pointed to by \a
other and the item pointed to by this iterator.
@@ -1221,7 +1221,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa QJsonObject::constBegin(), QJsonObject::constEnd()
*/
-/*! \fn QJsonObject::const_iterator::const_iterator(const QJsonObject *obj, int index)
+/*! \fn QJsonObject::const_iterator::const_iterator(const QJsonObject *obj, qsizetype index)
\internal
*/
@@ -1258,7 +1258,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
Returns a pointer to the current item.
*/
-/*! \fn const QJsonValue QJsonObject::const_iterator::operator[](int j)
+/*! \fn const QJsonValue QJsonObject::const_iterator::operator[](qsizetype j)
Returns the item at offset \a j from the item pointed to by this iterator (the item at
position \c{*this + j}).
@@ -1356,7 +1356,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
current item.
*/
-/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator+(int j) const
+/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator+(qsizetype j) const
Returns an iterator to the item at \a j positions forward from
this iterator. If \a j is negative, the iterator goes backward.
@@ -1366,7 +1366,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator-()
*/
-/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator-(int j) const
+/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator-(qsizetype j) const
Returns an iterator to the item at \a j positions backward from
this iterator. If \a j is negative, the iterator goes forward.
@@ -1376,7 +1376,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator+()
*/
-/*! \fn QJsonObject::const_iterator &QJsonObject::const_iterator::operator+=(int j)
+/*! \fn QJsonObject::const_iterator &QJsonObject::const_iterator::operator+=(qsizetype j)
Advances the iterator by \a j items. If \a j is negative, the
iterator goes backward.
@@ -1386,7 +1386,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator-=(), operator+()
*/
-/*! \fn QJsonObject::const_iterator &QJsonObject::const_iterator::operator-=(int j)
+/*! \fn QJsonObject::const_iterator &QJsonObject::const_iterator::operator-=(qsizetype j)
Makes the iterator go back by \a j items. If \a j is negative,
the iterator goes forward.
@@ -1396,7 +1396,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator+=(), operator-()
*/
-/*! \fn int QJsonObject::const_iterator::operator-(const_iterator other) const
+/*! \fn qsizetype QJsonObject::const_iterator::operator-(const_iterator other) const
Returns the number of items between the item pointed to by \a
other and the item pointed to by this iterator.
@@ -1406,7 +1406,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
/*!
\internal
*/
-bool QJsonObject::detach(uint reserve)
+bool QJsonObject::detach(qsizetype reserve)
{
if (!o)
return true;
@@ -1417,7 +1417,7 @@ bool QJsonObject::detach(uint reserve)
/*!
\internal
*/
-QString QJsonObject::keyAt(int i) const
+QString QJsonObject::keyAt(qsizetype i) const
{
Q_ASSERT(o && i >= 0 && i * 2 < o->elements.length());
return o->stringAt(i * 2);
@@ -1426,7 +1426,7 @@ QString QJsonObject::keyAt(int i) const
/*!
\internal
*/
-QJsonValue QJsonObject::valueAt(int i) const
+QJsonValue QJsonObject::valueAt(qsizetype i) const
{
if (!o || i < 0 || 2 * i + 1 >= o->elements.length())
return QJsonValue(QJsonValue::Undefined);
@@ -1436,7 +1436,7 @@ QJsonValue QJsonObject::valueAt(int i) const
/*!
\internal
*/
-void QJsonObject::setValueAt(int i, const QJsonValue &val)
+void QJsonObject::setValueAt(qsizetype i, const QJsonValue &val)
{
Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.length());
detach();
@@ -1451,7 +1451,7 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val)
/*!
\internal
*/
-void QJsonObject::removeAt(int index)
+void QJsonObject::removeAt(qsizetype index)
{
detach();
o->removeAt(2 * index + 1);
diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h
index 7dbf5a52b6..2d786e3665 100644
--- a/src/corelib/serialization/qjsonobject.h
+++ b/src/corelib/serialization/qjsonobject.h
@@ -87,9 +87,9 @@ public:
QVariantHash toVariantHash() const;
QStringList keys() const;
- int size() const;
- inline int count() const { return size(); }
- inline int length() const { return size(); }
+ qsizetype size() const;
+ inline qsizetype count() const { return size(); }
+ inline qsizetype length() const { return size(); }
bool isEmpty() const;
#if QT_STRINGVIEW_LEVEL < 2
@@ -129,13 +129,13 @@ public:
public:
typedef std::random_access_iterator_tag iterator_category;
- typedef int difference_type;
+ typedef qsizetype difference_type;
typedef QJsonValue value_type;
typedef QJsonValueRef reference;
typedef QJsonValueRef *pointer;
inline iterator() : item(static_cast<QJsonObject*>(nullptr), 0) { }
- inline iterator(QJsonObject *obj, int index) : item(obj, index) { }
+ inline iterator(QJsonObject *obj, qsizetype index) : item(obj, index) { }
constexpr iterator(const iterator &other) = default;
iterator &operator=(const iterator &other)
@@ -149,7 +149,7 @@ public:
inline QJsonValueRef value() const { return item; }
inline QJsonValueRef operator*() const { return item; }
inline QJsonValueRef *operator->() const { return &item; }
- const QJsonValueRef operator[](int j) { return { item.o, int(item.index) + j }; }
+ const QJsonValueRef operator[](qsizetype j) { return { item.o, qsizetype(item.index) + j }; }
inline bool operator==(const iterator &other) const
{ return item.o == other.item.o && item.index == other.item.index; }
@@ -165,12 +165,12 @@ public:
inline iterator operator++(int) { iterator r = *this; ++item.index; return r; }
inline iterator &operator--() { --item.index; return *this; }
inline iterator operator--(int) { iterator r = *this; --item.index; return r; }
- inline iterator operator+(int j) const
- { iterator r = *this; r.item.index += j; return r; }
- inline iterator operator-(int j) const { return operator+(-j); }
- inline iterator &operator+=(int j) { item.index += j; return *this; }
- inline iterator &operator-=(int j) { item.index -= j; return *this; }
- int operator-(iterator j) const { return item.index - j.item.index; }
+ inline iterator operator+(qsizetype j) const
+ { iterator r = *this; r.item.index += quint64(j); return r; }
+ inline iterator operator-(qsizetype j) const { return operator+(-j); }
+ inline iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
+ inline iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
+ qsizetype operator-(iterator j) const { return item.index - j.item.index; }
public:
inline bool operator==(const const_iterator &other) const
@@ -192,13 +192,13 @@ public:
public:
typedef std::random_access_iterator_tag iterator_category;
- typedef int difference_type;
+ typedef qsizetype difference_type;
typedef QJsonValue value_type;
typedef const QJsonValueRef reference;
typedef const QJsonValueRef *pointer;
inline const_iterator() : item(static_cast<QJsonObject*>(nullptr), 0) { }
- inline const_iterator(const QJsonObject *obj, int index)
+ inline const_iterator(const QJsonObject *obj, qsizetype index)
: item(const_cast<QJsonObject*>(obj), index) { }
inline const_iterator(const iterator &other)
: item(other.item) { }
@@ -215,7 +215,7 @@ public:
inline QJsonValueRef value() const { return item; }
inline const QJsonValueRef operator*() const { return item; }
inline const QJsonValueRef *operator->() const { return &item; }
- const QJsonValueRef operator[](int j) { return { item.o, int(item.index) + j }; }
+ const QJsonValueRef operator[](qsizetype j) { return { item.o, qsizetype(item.index) + j }; }
inline bool operator==(const const_iterator &other) const
{ return item.o == other.item.o && item.index == other.item.index; }
@@ -231,12 +231,12 @@ public:
inline const_iterator operator++(int) { const_iterator r = *this; ++item.index; return r; }
inline const_iterator &operator--() { --item.index; return *this; }
inline const_iterator operator--(int) { const_iterator r = *this; --item.index; return r; }
- inline const_iterator operator+(int j) const
- { const_iterator r = *this; r.item.index += j; return r; }
- inline const_iterator operator-(int j) const { return operator+(-j); }
- inline const_iterator &operator+=(int j) { item.index += j; return *this; }
- inline const_iterator &operator-=(int j) { item.index -= j; return *this; }
- int operator-(const_iterator j) const { return item.index - j.item.index; }
+ inline const_iterator operator+(qsizetype j) const
+ { const_iterator r = *this; r.item.index += quint64(j); return r; }
+ inline const_iterator operator-(qsizetype j) const { return operator+(-j); }
+ inline const_iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
+ inline const_iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
+ qsizetype operator-(const_iterator j) const { return item.index - j.item.index; }
inline bool operator==(const iterator &other) const
{ return item.o == other.item.o && item.index == other.item.index; }
@@ -280,7 +280,7 @@ public:
// STL compatibility
typedef QJsonValue mapped_type;
typedef QString key_type;
- typedef int size_type;
+ typedef qsizetype size_type;
inline bool empty() const { return isEmpty(); }
@@ -292,7 +292,7 @@ private:
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonObject &);
QJsonObject(QCborContainerPrivate *object);
- bool detach(uint reserve = 0);
+ bool detach(qsizetype reserve = 0);
template <typename T> QJsonValue valueImpl(T key) const;
template <typename T> QJsonValueRef atImpl(T key);
@@ -303,11 +303,11 @@ private:
template <typename T> const_iterator constFindImpl(T key) const;
template <typename T> iterator insertImpl(T key, const QJsonValue &value);
- QString keyAt(int i) const;
- QJsonValue valueAt(int i) const;
- void setValueAt(int i, const QJsonValue &val);
- void removeAt(int i);
- template <typename T> iterator insertAt(int i, T key, const QJsonValue &val, bool exists);
+ QString keyAt(qsizetype i) const;
+ QJsonValue valueAt(qsizetype i) const;
+ void setValueAt(qsizetype i, const QJsonValue &val);
+ void removeAt(qsizetype i);
+ template <typename T> iterator insertAt(qsizetype i, T key, const QJsonValue &val, bool exists);
QExplicitlySharedDataPointer<QCborContainerPrivate> o;
};
diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp
index 0f922f521a..0d31f4b756 100644
--- a/src/corelib/serialization/qjsonvalue.cpp
+++ b/src/corelib/serialization/qjsonvalue.cpp
@@ -101,7 +101,7 @@ QT_BEGIN_NAMESPACE
The following methods return QJsonValueRef:
\list
- \li \l {QJsonArray}::operator[](int i)
+ \li \l {QJsonArray}::operator[](qsizetype i)
\li \l {QJsonObject}::operator[](const QString & key) const
\endlist
@@ -840,7 +840,7 @@ const QJsonValue QJsonValue::operator[](QLatin1String key) const
\sa QJsonValue, QJsonValue::isUndefined(), QJsonArray
*/
-const QJsonValue QJsonValue::operator[](int i) const
+const QJsonValue QJsonValue::operator[](qsizetype i) const
{
if (!isArray())
return QJsonValue(QJsonValue::Undefined);
diff --git a/src/corelib/serialization/qjsonvalue.h b/src/corelib/serialization/qjsonvalue.h
index 734493984c..bda77aa0df 100644
--- a/src/corelib/serialization/qjsonvalue.h
+++ b/src/corelib/serialization/qjsonvalue.h
@@ -126,7 +126,7 @@ public:
#endif
const QJsonValue operator[](QStringView key) const;
const QJsonValue operator[](QLatin1String key) const;
- const QJsonValue operator[](int i) const;
+ const QJsonValue operator[](qsizetype i) const;
bool operator==(const QJsonValue &other) const;
bool operator!=(const QJsonValue &other) const;
@@ -159,10 +159,10 @@ private:
class Q_CORE_EXPORT QJsonValueRef
{
public:
- QJsonValueRef(QJsonArray *array, int idx)
- : a(array), is_object(false), index(static_cast<uint>(idx)) {}
- QJsonValueRef(QJsonObject *object, int idx)
- : o(object), is_object(true), index(static_cast<uint>(idx)) {}
+ QJsonValueRef(QJsonArray *array, qsizetype idx)
+ : a(array), is_object(false), index(static_cast<quint64>(idx)) {}
+ QJsonValueRef(QJsonObject *object, qsizetype idx)
+ : o(object), is_object(true), index(static_cast<quint64>(idx)) {}
QJsonValueRef(const QJsonValueRef &) = default;
@@ -182,6 +182,7 @@ public:
inline bool toBool(bool defaultValue = false) const { return toValue().toBool(defaultValue); }
inline int toInt(int defaultValue = 0) const { return toValue().toInt(defaultValue); }
+ inline qint64 toInteger(qint64 defaultValue = 0) const { return toValue().toInteger(defaultValue); }
inline double toDouble(double defaultValue = 0) const { return toValue().toDouble(defaultValue); }
inline QString toString(const QString &defaultValue = {}) const { return toValue().toString(defaultValue); }
QJsonArray toArray() const;
@@ -197,8 +198,8 @@ private:
QJsonArray *a;
QJsonObject *o;
};
- uint is_object : 1;
- uint index : 31;
+ quint64 is_object : 1;
+ quint64 index : 63;
friend class QJsonArray;
friend class QJsonObject;