Clean-up some Qt 5 leftovers from JSON serialization classes

Change-Id: I2ddf6901d627677395b39bec34c2c47d27e88d0b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Sona Kurazyan 2020-07-21 15:24:43 +02:00
parent 76d9d86907
commit 1c4ae44f6f
4 changed files with 17 additions and 108 deletions

View File

@ -158,22 +158,6 @@ QJsonArray::QJsonArray(QCborContainerPrivate *array)
Q_ASSERT(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.
*/
@ -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);

View File

@ -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);
bool detach(uint reserve = 0);
// ### Qt 6: remove
void *dead = nullptr;
QExplicitlySharedDataPointer<QCborContainerPrivate> a;
};

View File

@ -140,23 +140,6 @@ QJsonObject::QJsonObject(QCborContainerPrivate *object)
Q_ASSERT(o);
}
/*!
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.
*/
@ -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;
@ -1434,18 +1410,6 @@ bool QJsonObject::detach2(uint reserve)
return o;
}
/*!
\internal
*/
void QJsonObject::compact()
{
if (!o)
return;
detach2();
o->compact(o->elements.length());
}
/*!
\internal
*/
@ -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);
}

View File

@ -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;
};