aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Martins <[email protected]>2015-10-10 12:31:59 +0100
committerSergio Martins <[email protected]>2015-10-10 12:40:36 +0100
commitb179f4370a6a0e97681b991935e382b418ae01a7 (patch)
treee0eacf91cdd1a7db7e11a484aeb4520b13cf7264
parent04419240c10ce9b2ed2bc6654ccfb2658f94dcda (diff)
Avoid allocations due to QHash::keys() and QHash::values()
Moved two keys() calls into the qDebug() they where used to they aren't executed in release mode.
-rw-r--r--autotests/testblogger1.cpp2
-rw-r--r--autotests/testgdata.cpp2
-rw-r--r--autotests/testmetaweblog.cpp2
-rw-r--r--autotests/testmovabletype.cpp2
-rw-r--r--autotests/testwordpressbuggy.cpp2
-rw-r--r--src/blogger1.cpp4
-rw-r--r--src/metaweblog.cpp17
-rw-r--r--src/movabletype.cpp4
8 files changed, 16 insertions, 19 deletions
diff --git a/autotests/testblogger1.cpp b/autotests/testblogger1.cpp
index ef52c9c..7b13574 100644
--- a/autotests/testblogger1.cpp
+++ b/autotests/testblogger1.cpp
@@ -149,7 +149,7 @@ void TestBlogger1::listBlogs(const QList<QMap<QString, QString> > &listedBlogs)
QList<QMap<QString, QString> >::ConstIterator it = listedBlogs.begin();
QList<QMap<QString, QString> >::ConstIterator end = listedBlogs.end();
for (; it != end; ++it) {
- qDebug() << "# " << (*it).keys().first() << ": " << (*it).values().first();
+ qDebug() << "# " << (*it).cbegin().key() << ": " << (*it).cbegin().value();
}
qDebug() << "###########################\n";
diff --git a/autotests/testgdata.cpp b/autotests/testgdata.cpp
index ee19fc1..bac65c9 100644
--- a/autotests/testgdata.cpp
+++ b/autotests/testgdata.cpp
@@ -186,7 +186,7 @@ void TestGData::listBlogs(const QList<QMap<QString, QString> > &listedBlogs)
QList<QMap<QString, QString> >::ConstIterator it = listedBlogs.begin();
QList<QMap<QString, QString> >::ConstIterator end = listedBlogs.end();
for (; it != end; ++it) {
- qDebug() << "# " << (*it).values().first();
+ qDebug() << "# " << (*it).cbegin().value();
}
qDebug() << "###########################\n";
diff --git a/autotests/testmetaweblog.cpp b/autotests/testmetaweblog.cpp
index 265fdcb..567d0c6 100644
--- a/autotests/testmetaweblog.cpp
+++ b/autotests/testmetaweblog.cpp
@@ -154,7 +154,7 @@ void TestMetaWeblog::listBlogs(const QList<QMap<QString, QString> > &listedBlogs
QList<QMap<QString, QString> >::ConstIterator it = listedBlogs.begin();
QList<QMap<QString, QString> >::ConstIterator end = listedBlogs.end();
for (; it != end; ++it) {
- qDebug() << "# " << (*it).keys().first() << ": " << (*it).values().first();
+ qDebug() << "# " << (*it).cbegin().key() << ": " << (*it).cbegin().value();
}
qDebug() << "###########################\n";
diff --git a/autotests/testmovabletype.cpp b/autotests/testmovabletype.cpp
index 22fb140..5ae2683 100644
--- a/autotests/testmovabletype.cpp
+++ b/autotests/testmovabletype.cpp
@@ -160,7 +160,7 @@ void TestMovableType::listBlogs(const QList<QMap<QString, QString> > &listedBlog
QList<QMap<QString, QString> >::ConstIterator it = listedBlogs.begin();
QList<QMap<QString, QString> >::ConstIterator end = listedBlogs.end();
for (; it != end; ++it) {
- qDebug() << "# " << (*it).keys().first() << ": " << (*it).values().first();
+ qDebug() << "# " << (*it).cbegin().key() << ": " << (*it).cbegin().value();
}
qDebug() << "###########################\n";
diff --git a/autotests/testwordpressbuggy.cpp b/autotests/testwordpressbuggy.cpp
index f22bed7..a291f43 100644
--- a/autotests/testwordpressbuggy.cpp
+++ b/autotests/testwordpressbuggy.cpp
@@ -157,7 +157,7 @@ void TestWordpressBuggy::listBlogs(const QList<QMap<QString, QString> > &listedB
QList<QMap<QString, QString> >::ConstIterator it = listedBlogs.begin();
QList<QMap<QString, QString> >::ConstIterator end = listedBlogs.end();
for (; it != end; ++it) {
- qDebug() << "# " << (*it).keys().first() << ": " << (*it).values().first();
+ qDebug() << "# " << (*it).cbegin().key() << ": " << (*it).cbegin().value();
}
qDebug() << "###########################\n";
diff --git a/src/blogger1.cpp b/src/blogger1.cpp
index 2db9e4f..bb10ed4 100644
--- a/src/blogger1.cpp
+++ b/src/blogger1.cpp
@@ -464,8 +464,8 @@ bool Blogger1Private::readPostFromMap(
if (!post) {
return false;
}
- QStringList mapkeys = postInfo.keys();
- qCDebug(KBLOG_LOG) << endl << "Keys:" << mapkeys.join(QStringLiteral(", "));
+
+ qCDebug(KBLOG_LOG) << endl << "Keys:" << postInfo.keys().join(QStringLiteral(", "));
qCDebug(KBLOG_LOG) << endl;
QDateTime dt = postInfo[QStringLiteral("dateCreated")].toDateTime();
diff --git a/src/metaweblog.cpp b/src/metaweblog.cpp
index db85445..a2a2356 100644
--- a/src/metaweblog.cpp
+++ b/src/metaweblog.cpp
@@ -189,15 +189,12 @@ void MetaWeblogPrivate::slotListCategories(const QList<QVariant> &result,
} else {
if (result[0].type() == QVariant::Map) {
const QMap<QString, QVariant> serverMap = result[0].toMap();
- const QList<QString> serverKeys = serverMap.keys();
-
- QList<QString>::ConstIterator it = serverKeys.begin();
- QList<QString>::ConstIterator end = serverKeys.end();
- for (; it != end; ++it) {
- qCDebug(KBLOG_LOG) << "MIDDLE:" << (*it);
+ for (auto it = serverMap.cbegin(), end = serverMap.cend(); it != end; ++it) {
+ const QString &key = it.key();
+ qCDebug(KBLOG_LOG) << "MIDDLE:" << key;
QMap<QString, QString> category;
- const QMap<QString, QVariant> serverCategory = serverMap[*it].toMap();
- category[QStringLiteral("name")] = (*it);
+ const QMap<QString, QVariant> serverCategory = it.value().toMap();
+ category[QStringLiteral("name")] = key;
category[QStringLiteral("description")] = serverCategory[ QStringLiteral("description") ].toString();
category[QStringLiteral("htmlUrl")] = serverCategory[ QStringLiteral("htmlUrl") ].toString();
category[QStringLiteral("rssUrl")] = serverCategory[ QStringLiteral("rssUrl") ].toString();
@@ -270,8 +267,8 @@ bool MetaWeblogPrivate::readPostFromMap(BlogPost *post,
if (!post) {
return false;
}
- QStringList mapkeys = postInfo.keys();
- qCDebug(KBLOG_LOG) << endl << "Keys:" << mapkeys.join(QStringLiteral(", "));
+
+ qCDebug(KBLOG_LOG) << endl << "Keys:" << postInfo.keys().join(QStringLiteral(", "));
qCDebug(KBLOG_LOG) << endl;
QDateTime dt = postInfo[QStringLiteral("dateCreated")].toDateTime();
diff --git a/src/movabletype.cpp b/src/movabletype.cpp
index d0be684..e9f736b 100644
--- a/src/movabletype.cpp
+++ b/src/movabletype.cpp
@@ -459,8 +459,8 @@ bool MovableTypePrivate::readPostFromMap(BlogPost *post, const QMap<QString, QVa
if (!post) {
return false;
}
- QStringList mapkeys = postInfo.keys();
- qCDebug(KBLOG_LOG) << endl << "Keys:" << mapkeys.join(QStringLiteral(", "));
+
+ qCDebug(KBLOG_LOG) << endl << "Keys:" << postInfo.keys().join(QStringLiteral(", "));
qCDebug(KBLOG_LOG) << endl;
QDateTime dt = postInfo[QStringLiteral("dateCreated")].toDateTime();