From ebe4ab04ca156c64a5c56a6fca877654b451fe3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Martins?= Date: Wed, 1 Jul 2015 17:23:10 +0100 Subject: [PATCH] Use const-ref in foreach if T is big or non-trivial Criteria: Linux x86_64, sizeof(T) > 8 Change-Id: I78c2b776ff219fa1ff6632fde17ae25fae66c54e Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Marc Mutz --- src/plugins/bearer/connman/qconnmanservice_linux.cpp | 9 ++++----- src/plugins/bearer/linux_common/qofonoservice_linux.cpp | 4 ++-- src/tools/qdoc/htmlgenerator.cpp | 2 +- src/tools/qdoc/qdocdatabase.cpp | 4 ++-- src/tools/qlalr/compress.cpp | 2 +- src/tools/qlalr/cppgenerator.cpp | 4 ++-- src/tools/qlalr/lalr.cpp | 8 ++++---- src/tools/qlalr/parsetable.cpp | 2 +- src/widgets/dialogs/qfiledialog.cpp | 2 +- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/plugins/bearer/connman/qconnmanservice_linux.cpp b/src/plugins/bearer/connman/qconnmanservice_linux.cpp index d23d6e5f88..10d8285a4a 100644 --- a/src/plugins/bearer/connman/qconnmanservice_linux.cpp +++ b/src/plugins/bearer/connman/qconnmanservice_linux.cpp @@ -174,11 +174,10 @@ void QConnmanManagerInterface::connectNotify(const QMetaMethod &signal) void QConnmanManagerInterface::onServicesChanged(const ConnmanMapList &changed, const QList &removed) { - ConnmanMap connmanobj; servicesList.clear(); //connman list changes order - Q_FOREACH (connmanobj, changed) { + Q_FOREACH (const ConnmanMap &connmanobj, changed) { const QString svcPath(connmanobj.objectPath.path()); - servicesList << svcPath; + servicesList << svcPath; } Q_EMIT servicesChanged(changed, removed); @@ -220,7 +219,7 @@ QStringList QConnmanManagerInterface::getTechnologies() QDBusPendingReply reply = call(QLatin1String("GetTechnologies")); reply.waitForFinished(); if (!reply.isError()) { - Q_FOREACH (ConnmanMap map, reply.value()) { + Q_FOREACH (const ConnmanMap &map, reply.value()) { if (!technologiesMap.contains(map.objectPath.path())) { technologyAdded(map.objectPath, map.propertyMap); } @@ -236,7 +235,7 @@ QStringList QConnmanManagerInterface::getServices() QDBusPendingReply reply = call(QLatin1String("GetServices")); reply.waitForFinished(); if (!reply.isError()) { - Q_FOREACH (ConnmanMap map, reply.value()) { + Q_FOREACH (const ConnmanMap &map, reply.value()) { servicesList << map.objectPath.path(); } } diff --git a/src/plugins/bearer/linux_common/qofonoservice_linux.cpp b/src/plugins/bearer/linux_common/qofonoservice_linux.cpp index 9b83386abb..e9e91f9855 100644 --- a/src/plugins/bearer/linux_common/qofonoservice_linux.cpp +++ b/src/plugins/bearer/linux_common/qofonoservice_linux.cpp @@ -97,7 +97,7 @@ QStringList QOfonoManagerInterface::getModems() QDBusPendingReply reply = callWithArgumentList(QDBus::Block, QLatin1String("GetModems"), argumentList); reply.waitForFinished(); if (!reply.isError()) { - foreach (ObjectPathProperties modem, reply.value()) { + foreach (const ObjectPathProperties &modem, reply.value()) { modemList << modem.path.path(); } } @@ -260,7 +260,7 @@ QStringList QOfonoDataConnectionManagerInterface::contexts() QDBusPendingReply reply = call(QLatin1String("GetContexts")); reply.waitForFinished(); if (!reply.isError()) { - foreach (ObjectPathProperties context, reply.value()) { + foreach (const ObjectPathProperties &context, reply.value()) { contextList << context.path.path(); } } diff --git a/src/tools/qdoc/htmlgenerator.cpp b/src/tools/qdoc/htmlgenerator.cpp index 3dbb5a589f..6b92ea12a4 100644 --- a/src/tools/qdoc/htmlgenerator.cpp +++ b/src/tools/qdoc/htmlgenerator.cpp @@ -4589,7 +4589,7 @@ void HtmlGenerator::generateManifestFile(const QString &manifest, const QString if (!tags.isEmpty()) { writer.writeStartElement("tags"); bool wrote_one = false; - foreach (QString tag, tags) { + foreach (const QString &tag, tags) { if (wrote_one) writer.writeCharacters(","); writer.writeCharacters(tag); diff --git a/src/tools/qdoc/qdocdatabase.cpp b/src/tools/qdoc/qdocdatabase.cpp index 5d815d344f..b0f1758a84 100644 --- a/src/tools/qdoc/qdocdatabase.cpp +++ b/src/tools/qdoc/qdocdatabase.cpp @@ -167,7 +167,7 @@ void QDocForest::setSearchOrder(QStringList& t) forest_.remove(primaryName); QMap::iterator i; - foreach (QString m, t) { + foreach (const QString &m, t) { if (primaryName != m) { i = forest_.find(m); if (i != forest_.end()) { @@ -1296,7 +1296,7 @@ void QDocDatabase::resolveNamespaces() t = forest_.nextTree(); } QList keys = nmm_.uniqueKeys(); - foreach (QString s, keys) { + foreach (const QString &s, keys) { NamespaceNode* ns = 0; QList nodes = nmm_.values(s); int count = nmm_.remove(s); diff --git a/src/tools/qlalr/compress.cpp b/src/tools/qlalr/compress.cpp index 247b284421..fa67504a08 100644 --- a/src/tools/qlalr/compress.cpp +++ b/src/tools/qlalr/compress.cpp @@ -183,7 +183,7 @@ void Compress::operator () (int *table, int row_count, int column_count) index.fill (-999999, row_count); - foreach (UncompressedRow row, sortedTable) + foreach (const UncompressedRow &row, sortedTable) { int first_token = std::distance (row.begin (), row.beginNonZeros ()); QVector::iterator pos = info.begin (); diff --git a/src/tools/qlalr/cppgenerator.cpp b/src/tools/qlalr/cppgenerator.cpp index 80f7a4ed2b..3005690e6e 100644 --- a/src/tools/qlalr/cppgenerator.cpp +++ b/src/tools/qlalr/cppgenerator.cpp @@ -163,7 +163,7 @@ void CppGenerator::operator () () if (item->rule == grammar.goal) accept_state = q; - foreach (Name s, lookaheads) + foreach (const Name &s, lookaheads) { int &u = ACTION (q, aut.id (s)); @@ -616,7 +616,7 @@ void CppGenerator::generateImpl (QTextStream &out) out << name_ids.value(rule->lhs); - foreach (Name n, rule->rhs) + foreach (const Name &n, rule->rhs) out << ", " << name_ids.value (n); } out << "};" << endl << endl; diff --git a/src/tools/qlalr/lalr.cpp b/src/tools/qlalr/lalr.cpp index 3d0d5de19b..4470c8f07f 100644 --- a/src/tools/qlalr/lalr.cpp +++ b/src/tools/qlalr/lalr.cpp @@ -367,7 +367,7 @@ void Automaton::closure (StatePointer state) if (_M_grammar->isNonTerminal (*item->dot)) { - foreach (RulePointer rule, _M_grammar->rule_map.values (*item->dot)) + foreach (const RulePointer &rule, _M_grammar->rule_map.values (*item->dot)) { Item ii; ii.rule = rule; @@ -413,7 +413,7 @@ void Automaton::buildLookbackSets () if (! _M_grammar->isNonTerminal (A)) continue; - foreach (RulePointer rule, _M_grammar->rule_map.values (A)) + foreach (const RulePointer &rule, _M_grammar->rule_map.values (A)) { StatePointer q = p; @@ -606,7 +606,7 @@ void Automaton::buildIncludesDigraph () if (! _M_grammar->isNonTerminal (name)) continue; - foreach (RulePointer rule, _M_grammar->rule_map.values (name)) + foreach (const RulePointer &rule, _M_grammar->rule_map.values (name)) { StatePointer p = pp; @@ -706,7 +706,7 @@ void Automaton::buildLookaheads () { for (ItemPointer item = p->closure.begin (); item != p->closure.end (); ++item) { - foreach (Lookback lookback, lookbacks.values (item)) + foreach (const Lookback &lookback, lookbacks.values (item)) { StatePointer q = lookback.state; diff --git a/src/tools/qlalr/parsetable.cpp b/src/tools/qlalr/parsetable.cpp index 8b62e597ef..77e2219987 100644 --- a/src/tools/qlalr/parsetable.cpp +++ b/src/tools/qlalr/parsetable.cpp @@ -91,7 +91,7 @@ void ParseTable::operator () (Automaton *aut) first = false; - foreach (Name la, aut->lookaheads.value (item)) + foreach (const Name &la, aut->lookaheads.value (item)) out << " " << *la << " reduce using rule " << aut->id (item->rule) << " (" << *item->rule->lhs << ")" << endl; } diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index d83f6609b8..a200fd4d4c 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -2972,7 +2972,7 @@ void QFileDialogPrivate::createWidgets() q->setHistory(options->history()); if (options->initiallySelectedFiles().count() == 1) q->selectFile(options->initiallySelectedFiles().first().fileName()); - foreach (QUrl url, options->initiallySelectedFiles()) + foreach (const QUrl &url, options->initiallySelectedFiles()) q->selectUrl(url); lineEdit()->selectAll(); _q_updateOkButton();