diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-07-21 15:24:43 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-07-22 09:33:52 +0200 |
commit | 1c4ae44f6f15bcb40d329668756d9a9456ab9348 (patch) | |
tree | b3a3148cafe278dcbc7d0b832bdf045344787f4f /src | |
parent | 76d9d869072d22995fa2cc6cb5fec17c42230dc4 (diff) |
Clean-up some Qt 5 leftovers from JSON serialization classes
Change-Id: I2ddf6901d627677395b39bec34c2c47d27e88d0b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/serialization/qjsonarray.cpp | 50 | ||||
-rw-r--r-- | src/corelib/serialization/qjsonarray.h | 17 | ||||
-rw-r--r-- | src/corelib/serialization/qjsonobject.cpp | 48 | ||||
-rw-r--r-- | src/corelib/serialization/qjsonobject.h | 12 |
4 files changed, 18 insertions, 109 deletions
diff --git a/src/corelib/serialization/qjsonarray.cpp b/src/corelib/serialization/qjsonarray.cpp index bc28c18edd..f13228af43 100644 --- a/src/corelib/serialization/qjsonarray.cpp +++ b/src/corelib/serialization/qjsonarray.cpp @@ -159,22 +159,6 @@ QJsonArray::QJsonArray(QCborContainerPrivate *array) } /*! - This method replaces part of QJsonArray(std::initializer_list<QJsonValue> args) . - The constructor needs to be inline, but we do not want to leak implementation details - of this class. - \note this method is called for an uninitialized object - \internal - */ -void QJsonArray::initialize() -{ - // Because we're being called with uninitialized state, we can't do: - // a = nullptr; - // QExplicitlyDataSharedPointer::operator= will read the current value - void *ptr = &a; - memset(ptr, 0, sizeof(a)); -} - -/*! Deletes the array. */ QJsonArray::~QJsonArray() = default; @@ -391,7 +375,7 @@ void QJsonArray::removeAt(int i) { if (!a || i < 0 || i >= a->elements.length()) return; - detach2(); + detach(); a->removeAt(i); } @@ -428,7 +412,7 @@ QJsonValue QJsonArray::takeAt(int i) if (!a || i < 0 || i >= a->elements.length()) return QJsonValue(QJsonValue::Undefined); - detach2(); + detach(); const QJsonValue v = QJsonPrivate::Value::fromTrustedCbor(a->extractAt(i)); a->removeAt(i); return v; @@ -444,7 +428,7 @@ QJsonValue QJsonArray::takeAt(int i) void QJsonArray::insert(int i, const QJsonValue &value) { if (a) - detach2(a->elements.length() + 1); + detach(a->elements.length() + 1); else a = new QCborContainerPrivate; @@ -480,7 +464,7 @@ void QJsonArray::insert(int i, const QJsonValue &value) void QJsonArray::replace(int i, const QJsonValue &value) { Q_ASSERT (a && i >= 0 && i < a->elements.length()); - detach2(); + detach(); a->replaceAt(i, QCborValue::fromJsonValue(value)); } @@ -952,11 +936,6 @@ bool QJsonArray::operator!=(const QJsonArray &other) const \internal */ -/*! \fn QJsonArray::const_iterator::const_iterator(const const_iterator &other) - - Constructs a copy of \a other. -*/ - /*! \fn QJsonArray::const_iterator::const_iterator(const iterator &other) Constructs a copy of \a other. @@ -1103,21 +1082,10 @@ bool QJsonArray::operator!=(const QJsonArray &other) const other and the item pointed to by this iterator. */ - /*! \internal */ -void QJsonArray::detach(uint reserve) -{ - Q_UNUSED(reserve); - Q_ASSERT(!reserve); - detach2(0); -} - -/*! - \internal - */ -bool QJsonArray::detach2(uint reserve) +bool QJsonArray::detach(uint reserve) { if (!a) return true; @@ -1125,14 +1093,6 @@ bool QJsonArray::detach2(uint reserve) return a; } -/*! - \internal - */ -void QJsonArray::compact() -{ - a->compact(a->elements.size()); -} - size_t qHash(const QJsonArray &array, size_t seed) { return qHashRange(array.begin(), array.end(), seed); diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h index 4466210ce6..5cf046fbe0 100644 --- a/src/corelib/serialization/qjsonarray.h +++ b/src/corelib/serialization/qjsonarray.h @@ -164,9 +164,6 @@ public: inline const_iterator() : a(nullptr), i(0) { } explicit inline const_iterator(const QJsonArray *array, int index) : a(array), i(index) { } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - inline const_iterator(const const_iterator &o) : a(o.a), i(o.i) {} // ### Qt 6: Removed so class can be trivially-copyable -#endif inline const_iterator(const iterator &o) : a(o.a), i(o.i) {} inline QJsonValue operator*() const { return a->at(i); } @@ -195,11 +192,11 @@ public: friend class const_iterator; // stl style - inline iterator begin() { detach2(); return iterator(this, 0); } + inline iterator begin() { detach(); return iterator(this, 0); } inline const_iterator begin() const { return const_iterator(this, 0); } inline const_iterator constBegin() const { return const_iterator(this, 0); } inline const_iterator cbegin() const { return const_iterator(this, 0); } - inline iterator end() { detach2(); return iterator(this, size()); } + inline iterator end() { detach(); return iterator(this, size()); } inline const_iterator end() const { return const_iterator(this, size()); } inline const_iterator constEnd() const { return const_iterator(this, size()); } inline const_iterator cend() const { return const_iterator(this, size()); } @@ -239,14 +236,8 @@ private: friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &); QJsonArray(QCborContainerPrivate *array); - void initialize(); - void compact(); - // ### Qt 6: remove me and merge with detach2 - void detach(uint reserve = 0); - bool detach2(uint reserve = 0); - - // ### Qt 6: remove - void *dead = nullptr; + bool detach(uint reserve = 0); + QExplicitlySharedDataPointer<QCborContainerPrivate> a; }; diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index 1c7fb7885f..6befa9d2eb 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -141,23 +141,6 @@ QJsonObject::QJsonObject(QCborContainerPrivate *object) } /*! - This method replaces part of the QJsonObject(std::initializer_list<QPair<QString, QJsonValue>> args) body. - The constructor needs to be inline, but we do not want to leak implementation details - of this class. - \note this method is called for an uninitialized object - \internal - */ - -void QJsonObject::initialize() -{ - // Because we're being called with uninitialized state, we can't do: - // o = nullptr; - // QExplicitlyDataSharedPointer::operator= will read the current value - void *ptr = &o; - memset(ptr, 0, sizeof(o)); -} - -/*! Destroys the object. */ QJsonObject::~QJsonObject() = default; @@ -452,7 +435,7 @@ QJsonValueRef QJsonObject::atImpl(T key) bool keyExists = false; int index = indexOf(o, key, &keyExists); if (!keyExists) { - detach2(o->elements.length() / 2 + 1); + detach(o->elements.length() / 2 + 1); o->insertAt(index, key); o->insertAt(index + 1, QCborValue::fromJsonValue(QJsonValue())); } @@ -520,7 +503,7 @@ template <typename T> QJsonObject::iterator QJsonObject::insertAt(int pos, T key, const QJsonValue &value, bool keyExists) { if (o) - detach2(o->elements.length() / 2 + (keyExists ? 0 : 1)); + detach(o->elements.length() / 2 + (keyExists ? 0 : 1)); else o = new QCborContainerPrivate; @@ -770,7 +753,7 @@ QJsonObject::iterator QJsonObject::findImpl(T key) int index = o ? indexOf(o, key, &keyExists) : 0; if (!keyExists) return end(); - detach2(); + detach(); return {this, index / 2}; } @@ -1419,14 +1402,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const /*! \internal */ -void QJsonObject::detach(uint reserve) -{ - Q_UNUSED(reserve); - Q_ASSERT(!reserve); - detach2(reserve); -} - -bool QJsonObject::detach2(uint reserve) +bool QJsonObject::detach(uint reserve) { if (!o) return true; @@ -1437,18 +1413,6 @@ bool QJsonObject::detach2(uint reserve) /*! \internal */ -void QJsonObject::compact() -{ - if (!o) - return; - - detach2(); - o->compact(o->elements.length()); -} - -/*! - \internal - */ QString QJsonObject::keyAt(int i) const { Q_ASSERT(o && i >= 0 && i * 2 < o->elements.length()); @@ -1471,7 +1435,7 @@ QJsonValue QJsonObject::valueAt(int i) const void QJsonObject::setValueAt(int i, const QJsonValue &val) { Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.length()); - detach2(); + detach(); if (val.isUndefined()) { o->removeAt(2 * i + 1); o->removeAt(2 * i); @@ -1485,7 +1449,7 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val) */ void QJsonObject::removeAt(int index) { - detach2(); + detach(); o->removeAt(2 * index + 1); o->removeAt(2 * index); } diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h index 4002a8bc24..09fdbfe54b 100644 --- a/src/corelib/serialization/qjsonobject.h +++ b/src/corelib/serialization/qjsonobject.h @@ -233,10 +233,10 @@ public: friend class const_iterator; // STL style - inline iterator begin() { detach2(); return iterator(this, 0); } + inline iterator begin() { detach(); return iterator(this, 0); } inline const_iterator begin() const { return const_iterator(this, 0); } inline const_iterator constBegin() const { return const_iterator(this, 0); } - inline iterator end() { detach2(); return iterator(this, size()); } + inline iterator end() { detach(); return iterator(this, size()); } inline const_iterator end() const { return const_iterator(this, size()); } inline const_iterator constEnd() const { return const_iterator(this, size()); } iterator erase(iterator it); @@ -274,11 +274,7 @@ private: friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonObject &); QJsonObject(QCborContainerPrivate *object); - void initialize(); - // ### Qt 6: remove me and merge with detach2 - void detach(uint reserve = 0); - bool detach2(uint reserve = 0); - void compact(); + bool detach(uint reserve = 0); template <typename T> QJsonValue valueImpl(T key) const; template <typename T> QJsonValueRef atImpl(T key); @@ -295,8 +291,6 @@ private: void removeAt(int i); template <typename T> iterator insertAt(int i, T key, const QJsonValue &val, bool exists); - // ### Qt 6: remove - void *dead = nullptr; QExplicitlySharedDataPointer<QCborContainerPrivate> o; }; |