Use by-ref in foreach when T is large or non-trivial
authorSérgio Martins <sergio.martins@kdab.com>
Sat, 4 Jul 2015 09:15:15 +0000 (10:15 +0100)
committerSérgio Martins <sergio.martins@kdab.com>
Sat, 18 Jul 2015 19:41:11 +0000 (19:41 +0000)
Change-Id: I79271fdc3fa064e362dfaa64ff11d8a4c6b7e8c3
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/imports/folderlistmodel/fileinfothread.cpp
src/qml/compiler/qqmltypecompiler.cpp
src/qml/debugger/qv4debugservice.cpp
src/quick/items/context2d/qquickcontext2d.cpp
tools/qmlimportscanner/main.cpp

index 532815e..ebdfba4 100644 (file)
@@ -252,7 +252,7 @@ void FileInfoThread::getFileInfos(const QString &path)
 
     if (!fileInfoList.isEmpty()) {
         filePropertyList.reserve(fileInfoList.count());
-        foreach (QFileInfo info, fileInfoList) {
+        foreach (const QFileInfo &info, fileInfoList) {
             //qDebug() << "Adding file : " << info.fileName() << "to list ";
             filePropertyList << FileProperty(info);
         }
index 61b538e..4a20959 100644 (file)
@@ -2017,7 +2017,7 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD
         customParserBindingsPerObject->insert(objectIndex, customParserBindings);
         const QList<QQmlError> parserErrors = customParser->errors();
         if (!parserErrors.isEmpty()) {
-            foreach (QQmlError error, parserErrors)
+            foreach (const QQmlError &error, parserErrors)
                 compiler->recordError(error);
             return false;
         }
index dade30e..0fe6f06 100644 (file)
@@ -813,7 +813,7 @@ public:
         QJsonArray handles = arguments.value(QStringLiteral("handles")).toArray();
 
         QJsonObject body;
-        foreach (QJsonValue handle, handles)
+        foreach (const QJsonValue &handle, handles)
             body[QString::number(handle.toInt())] = debugServicePrivate->lookup(handle.toInt());
 
         // response:
@@ -1221,7 +1221,7 @@ void QV4DebuggerAgent::debuggerPaused(QV4::Debugging::Debugger *debugger, QV4::D
 void QV4DebuggerAgent::sourcesCollected(QV4::Debugging::Debugger *debugger, QStringList sources, int requestSequenceNr)
 {
     QJsonArray body;
-    foreach (const QString source, sources) {
+    foreach (const QString &source, sources) {
         QJsonObject src;
         src[QLatin1String("name")] = source;
         src[QLatin1String("scriptType")] = 4;
index 1ebbe3b..0a09ee4 100644 (file)
@@ -300,7 +300,7 @@ static QStringList qExtractFontFamiliesFromString(const QString &fontFamiliesStr
 */
 static bool qSetFontFamilyFromTokens(QFont &font, const QStringList &fontFamilyTokens)
 {
-    foreach (QString fontFamilyToken, fontFamilyTokens) {
+    foreach (const QString &fontFamilyToken, fontFamilyTokens) {
         QFontDatabase fontDatabase;
         if (fontDatabase.hasFamily(fontFamilyToken)) {
             font.setFamily(fontFamilyToken);
@@ -411,7 +411,7 @@ static QFont qt_font_from_string(const QString& fontString, const QFont &current
 
     int usedTokens = NoTokens;
     // Optional properties can be in any order, but font-size and font-family must be last.
-    foreach (const QString token, tokens) {
+    foreach (const QString &token, tokens) {
         if (token.compare(QLatin1String("normal")) == 0) {
             if (!(usedTokens & FontStyle) || !(usedTokens & FontVariant) || !(usedTokens & FontWeight)) {
                 // Could be font-style, font-variant or font-weight.
index beb47e4..777ee1f 100644 (file)
@@ -199,7 +199,7 @@ QVariantList findPathsForModuleImports(const QVariantList &imports)
                 import[QStringLiteral("classname")] = classnames;
             if (plugininfo.contains(QStringLiteral("dependencies"))) {
                 QStringList dependencies = plugininfo.value(QStringLiteral("dependencies")).toStringList();
-                foreach (QString line, dependencies) {
+                foreach (const QString &line, dependencies) {
                     QList<QString> dep = line.split(QStringLiteral(" "));
                     QVariantMap depImport;
                     depImport[QStringLiteral("type")] = QStringLiteral("module");