Commit f71bc5ad authored by Anton Kudryavtsev's avatar Anton Kudryavtsev Committed by Oswald Buddenhagen

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: default avatarOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
(cherry picked from qtbase/69ab28031549ff1c9ceecdcb29197900e9bc4328)
Reviewed-by: Jake Petroules's avatarJake Petroules <jake.petroules@qt.io>
Reviewed-by: default avatarAnton Kudryavtsev <a.kudryavtsev@netris.ru>
parent 3f4e40e3
......@@ -296,7 +296,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);
}
......@@ -305,10 +307,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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment