diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2022-09-30 14:09:04 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-04 07:40:08 +0200 |
| commit | df9d882d41b741fef7c5beeddb0abe9d904443d8 (patch) | |
| tree | 6f3e90dacad4581b7f1cabe235cca298833a3da4 /src/corelib/serialization/qjsonobject.cpp | |
| parent | 109e088c7c5d0c9325966e88d55fd9f7a58f67ea (diff) | |
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).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'.
<classes> 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 <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/serialization/qjsonobject.cpp')
| -rw-r--r-- | src/corelib/serialization/qjsonobject.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
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 <typename T> 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); |
