qmake: optimize container usage in the json handling.
Iterate only once over QJsonObject, create key list by existing loop instead of create by QJsonObject::keys(), which contains internal loop. In common case if loop's statement is lightweight, then effect of optimization is significant, and vice versa. Also make addJsonArray() and addJsonObject() functions more homogeneous. Use reserve to optimize memory allocation. Change-Id: Id122cd1becfd34bb06640876b1c79e1d396d2a6b Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
parent
20a2ba6d74
commit
69ab280315
@ -295,7 +295,9 @@ static void insertJsonKeyValue(const QString &key, const QStringList &values, Pr
|
||||
static void addJsonArray(const QJsonArray &array, const QString &keyPrefix, ProValueMap *map)
|
||||
{
|
||||
QStringList keys;
|
||||
for (int i = 0; i < array.count(); ++i) {
|
||||
const int size = array.count();
|
||||
keys.reserve(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
keys.append(QString::number(i));
|
||||
addJsonValue(array.at(i), keyPrefix + QString::number(i), map);
|
||||
}
|
||||
@ -304,10 +306,14 @@ static void addJsonArray(const QJsonArray &array, const QString &keyPrefix, ProV
|
||||
|
||||
static void addJsonObject(const QJsonObject &object, const QString &keyPrefix, ProValueMap *map)
|
||||
{
|
||||
for (auto it = object.begin(), end = object.end(); it != end; ++it)
|
||||
addJsonValue(it.value(), keyPrefix + it.key(), map);
|
||||
|
||||
insertJsonKeyValue(keyPrefix + QLatin1String("_KEYS_"), object.keys(), map);
|
||||
QStringList keys;
|
||||
keys.reserve(object.size());
|
||||
for (auto it = object.begin(), end = object.end(); it != end; ++it) {
|
||||
const QString key = it.key();
|
||||
keys.append(key);
|
||||
addJsonValue(it.value(), keyPrefix + key, map);
|
||||
}
|
||||
insertJsonKeyValue(keyPrefix + QLatin1String("_KEYS_"), keys, map);
|
||||
}
|
||||
|
||||
static void addJsonValue(const QJsonValue &value, const QString &keyPrefix, ProValueMap *map)
|
||||
|
Loading…
x
Reference in New Issue
Block a user