QCborArray: use QCborValueConstRef

Change-Id: I5e52dc5b093c43a3b678fffd16b6077e5c4abd63
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
Thiago Macieira 2021-11-09 16:22:33 -08:00
parent 04dc959d49
commit 64d568b550
3 changed files with 11 additions and 10 deletions

View File

@ -233,7 +233,7 @@ inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path)
metaDataOk = true; metaDataOk = true;
const QCborArray k = object.value(QLatin1String("Keys")).toArray(); const QCborArray k = object.value(QLatin1String("Keys")).toArray();
for (QCborValueRef v : k) for (QCborValueConstRef v : k)
keys += cs ? v.toString() : v.toString().toLower(); keys += cs ? v.toString() : v.toString().toLower();
} }
qCDebug(lcFactoryLoader) << "Got keys from plugin meta data" << keys; qCDebug(lcFactoryLoader) << "Got keys from plugin meta data" << keys;
@ -435,7 +435,7 @@ QMultiMap<int, QString> QFactoryLoader::keyMap() const
for (int i = 0; i < metaDataList.size(); ++i) { for (int i = 0; i < metaDataList.size(); ++i) {
const QCborMap metaData = metaDataList.at(i).value(QtPluginMetaDataKeys::MetaData).toMap(); const QCborMap metaData = metaDataList.at(i).value(QtPluginMetaDataKeys::MetaData).toMap();
const QCborArray keys = metaData.value(QLatin1String("Keys")).toArray(); const QCborArray keys = metaData.value(QLatin1String("Keys")).toArray();
for (QCborValueRef key : keys) for (QCborValueConstRef key : keys)
result.insert(i, key.toString()); result.insert(i, key.toString());
} }
return result; return result;
@ -447,7 +447,7 @@ int QFactoryLoader::indexOf(const QString &needle) const
for (int i = 0; i < metaDataList.size(); ++i) { for (int i = 0; i < metaDataList.size(); ++i) {
const QCborMap metaData = metaDataList.at(i).value(QtPluginMetaDataKeys::MetaData).toMap(); const QCborMap metaData = metaDataList.at(i).value(QtPluginMetaDataKeys::MetaData).toMap();
const QCborArray keys = metaData.value(QLatin1String("Keys")).toArray(); const QCborArray keys = metaData.value(QLatin1String("Keys")).toArray();
for (QCborValueRef key : keys) { for (QCborValueConstRef key : keys) {
if (key.toString().compare(needle, Qt::CaseInsensitive) == 0) if (key.toString().compare(needle, Qt::CaseInsensitive) == 0)
return i; return i;
} }

View File

@ -57,7 +57,7 @@ class Q_CORE_EXPORT QCborArray
public: public:
class ConstIterator; class ConstIterator;
class Iterator { class Iterator {
mutable QCborValueRef item; QCborValueRef item {};
friend class ConstIterator; friend class ConstIterator;
friend class QCborArray; friend class QCborArray;
Iterator(QCborContainerPrivate *dd, qsizetype ii) : item(dd, ii) {} Iterator(QCborContainerPrivate *dd, qsizetype ii) : item(dd, ii) {}
@ -79,7 +79,8 @@ public:
} }
QCborValueRef operator*() const { return item; } QCborValueRef operator*() const { return item; }
QCborValueRef *operator->() const { return &item; } QCborValueRef *operator->() { return &item; }
const QCborValueConstRef *operator->() const { return &item; }
QCborValueRef operator[](qsizetype j) const { return { item.d, item.i + j }; } QCborValueRef operator[](qsizetype j) const { return { item.d, item.i + j }; }
bool operator==(const Iterator &o) const { return item.d == o.item.d && item.i == o.item.i; } bool operator==(const Iterator &o) const { return item.d == o.item.d && item.i == o.item.i; }
@ -106,7 +107,7 @@ public:
}; };
class ConstIterator { class ConstIterator {
QCborValueRef item; QCborValueConstRef item;
friend class Iterator; friend class Iterator;
friend class QCborArray; friend class QCborArray;
ConstIterator(QCborContainerPrivate *dd, qsizetype ii) : item(dd, ii) {} ConstIterator(QCborContainerPrivate *dd, qsizetype ii) : item(dd, ii) {}
@ -127,9 +128,9 @@ public:
return *this; return *this;
} }
const QCborValueRef operator*() const { return item; } QCborValueConstRef operator*() const { return item; }
const QCborValueRef *operator->() const { return &item; } const QCborValueConstRef *operator->() const { return &item; }
QCborValueRef operator[](qsizetype j) const { return QCborValueRef{ item.d, item.i + j }; } QCborValueConstRef operator[](qsizetype j) const { return QCborValueRef{ item.d, item.i + j }; }
bool operator==(const Iterator &o) const { return item.d == o.item.d && item.i == o.item.i; } bool operator==(const Iterator &o) const { return item.d == o.item.d && item.i == o.item.i; }
bool operator!=(const Iterator &o) const { return !(*this == o); } bool operator!=(const Iterator &o) const { return !(*this == o); }

View File

@ -326,7 +326,7 @@ struct QCborValueFormatter
{ {
QByteArray out(1, '['); QByteArray out(1, '[');
const char *comma = ""; const char *comma = "";
for (const QCborValueRef v : a) { for (QCborValueConstRef v : a) {
QScopedArrayPointer<char> s(format(v)); QScopedArrayPointer<char> s(format(v));
out += comma; out += comma;
out += s.get(); out += s.get();