From df9d882d41b741fef7c5beeddb0abe9d904443d8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 30 Sep 2022 14:09:04 +0200 Subject: Port from container.count()/length() to size() This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName()))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- src/corelib/serialization/qjsonobject.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/corelib/serialization/qjsonobject.cpp') diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index 1fdcbef829b..ab482876af7 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -228,8 +228,8 @@ QStringList QJsonObject::keys() const { QStringList keys; if (o) { - keys.reserve(o->elements.length() / 2); - for (qsizetype i = 0, end = o->elements.length(); i < end; i += 2) + keys.reserve(o->elements.size() / 2); + for (qsizetype i = 0, end = o->elements.size(); i < end; i += 2) keys.append(o->stringAt(i)); } return keys; @@ -240,7 +240,7 @@ QStringList QJsonObject::keys() const */ qsizetype QJsonObject::size() const { - return o ? o->elements.length() / 2 : 0; + return o ? o->elements.size() / 2 : 0; } /*! @@ -392,7 +392,7 @@ QJsonValueRef QJsonObject::atImpl(T key) bool keyExists = false; auto index = indexOf(o, key, &keyExists); if (!keyExists) { - detach(o->elements.length() / 2 + 1); + detach(o->elements.size() / 2 + 1); o->insertAt(index, key); o->insertAt(index + 1, QCborValue::fromJsonValue(QJsonValue())); } @@ -458,7 +458,7 @@ template QJsonObject::iterator QJsonObject::insertAt(qsizetype pos, T key, const QJsonValue &value, bool keyExists) { if (o) - detach(o->elements.length() / 2 + (keyExists ? 0 : 1)); + detach(o->elements.size() / 2 + (keyExists ? 0 : 1)); else o = new QCborContainerPrivate; @@ -619,13 +619,13 @@ bool QJsonObject::operator==(const QJsonObject &other) const return true; if (!o) - return !other.o->elements.length(); + return !other.o->elements.size(); if (!other.o) - return !o->elements.length(); - if (o->elements.length() != other.o->elements.length()) + return !o->elements.size(); + if (o->elements.size() != other.o->elements.size()) return false; - for (qsizetype i = 0, end = o->elements.length(); i < end; ++i) { + for (qsizetype i = 0, end = o->elements.size(); i < end; ++i) { if (o->valueAt(i) != other.o->valueAt(i)) return false; } @@ -1352,7 +1352,7 @@ bool QJsonObject::detach(qsizetype reserve) { if (!o) return true; - o = QCborContainerPrivate::detach(o.data(), reserve ? reserve * 2 : o->elements.length()); + o = QCborContainerPrivate::detach(o.data(), reserve ? reserve * 2 : o->elements.size()); return o; } @@ -1362,7 +1362,7 @@ bool QJsonObject::detach(qsizetype reserve) */ QString QJsonObject::keyAt(qsizetype i) const { - Q_ASSERT(o && i >= 0 && i * 2 < o->elements.length()); + Q_ASSERT(o && i >= 0 && i * 2 < o->elements.size()); return o->stringAt(i * 2); } @@ -1371,7 +1371,7 @@ QString QJsonObject::keyAt(qsizetype i) const */ QJsonValue QJsonObject::valueAt(qsizetype i) const { - if (!o || i < 0 || 2 * i + 1 >= o->elements.length()) + if (!o || i < 0 || 2 * i + 1 >= o->elements.size()) return QJsonValue(QJsonValue::Undefined); return QJsonPrivate::Value::fromTrustedCbor(o->valueAt(2 * i + 1)); } @@ -1381,7 +1381,7 @@ QJsonValue QJsonObject::valueAt(qsizetype i) const */ void QJsonObject::setValueAt(qsizetype i, const QJsonValue &val) { - Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.length()); + Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.size()); detach(); if (val.isUndefined()) { o->removeAt(2 * i + 1); -- cgit v1.2.3