forked from qt-creator/qt-creator
qmake: eradicate Q_FOREACH loops [rvalues]
... by replacing them with C++11 range-for loops. This is the simplest of the patch series: Q_FOREACH took a copy, so we do, too. Except we don't, since we're just catching the return value that comes out of the function (RVO). We can't feed the rvalues into range-for, because they are non-const and would thus detach. Change-Id: I5834620bf82f3442da7b2838363d351a0fb960a0 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> (cherry picked from qtbase/8d7e913248aa1cad23447668d98911bba01faf4b) Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
committed by
Oswald Buddenhagen
parent
ccdcbc55ca
commit
1a4f0f1dad
@@ -493,14 +493,15 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!var.isEmpty()) {
|
if (!var.isEmpty()) {
|
||||||
|
const auto strings = values(map(var));
|
||||||
if (regexp) {
|
if (regexp) {
|
||||||
QRegExp sepRx(sep);
|
QRegExp sepRx(sep);
|
||||||
foreach (const ProString &str, values(map(var))) {
|
for (const ProString &str : strings) {
|
||||||
const QString &rstr = str.toQString(m_tmp1).section(sepRx, beg, end);
|
const QString &rstr = str.toQString(m_tmp1).section(sepRx, beg, end);
|
||||||
ret << (rstr.isSharedWith(m_tmp1) ? str : ProString(rstr).setSource(str));
|
ret << (rstr.isSharedWith(m_tmp1) ? str : ProString(rstr).setSource(str));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach (const ProString &str, values(map(var))) {
|
for (const ProString &str : strings) {
|
||||||
const QString &rstr = str.toQString(m_tmp1).section(sep, beg, end);
|
const QString &rstr = str.toQString(m_tmp1).section(sep, beg, end);
|
||||||
ret << (rstr.isSharedWith(m_tmp1) ? str : ProString(rstr).setSource(str));
|
ret << (rstr.isSharedWith(m_tmp1) ? str : ProString(rstr).setSource(str));
|
||||||
}
|
}
|
||||||
@@ -529,7 +530,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
|
|||||||
bool leftalign = false;
|
bool leftalign = false;
|
||||||
enum { DefaultSign, PadSign, AlwaysSign } sign = DefaultSign;
|
enum { DefaultSign, PadSign, AlwaysSign } sign = DefaultSign;
|
||||||
if (args.count() >= 2) {
|
if (args.count() >= 2) {
|
||||||
foreach (const ProString &opt, split_value_list(args.at(1).toQString(m_tmp2))) {
|
const auto opts = split_value_list(args.at(1).toQString(m_tmp2));
|
||||||
|
for (const ProString &opt : opts) {
|
||||||
opt.toQString(m_tmp3);
|
opt.toQString(m_tmp3);
|
||||||
if (m_tmp3.startsWith(QLatin1String("ibase="))) {
|
if (m_tmp3.startsWith(QLatin1String("ibase="))) {
|
||||||
ibase = m_tmp3.mid(6).toInt();
|
ibase = m_tmp3.mid(6).toInt();
|
||||||
@@ -618,9 +620,12 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
|
|||||||
evalError(fL1S("split(var, sep) requires one or two arguments."));
|
evalError(fL1S("split(var, sep) requires one or two arguments."));
|
||||||
} else {
|
} else {
|
||||||
const QString &sep = (args.count() == 2) ? args.at(1).toQString(m_tmp1) : statics.field_sep;
|
const QString &sep = (args.count() == 2) ? args.at(1).toQString(m_tmp1) : statics.field_sep;
|
||||||
foreach (const ProString &var, values(map(args.at(0))))
|
const auto vars = values(map(args.at(0)));
|
||||||
foreach (const QString &splt, var.toQString(m_tmp2).split(sep))
|
for (const ProString &var : vars) {
|
||||||
|
const auto splits = var.toQString(m_tmp2).split(sep);
|
||||||
|
for (const QString &splt : splits)
|
||||||
ret << (splt.isSharedWith(m_tmp2) ? var : ProString(splt).setSource(var));
|
ret << (splt.isSharedWith(m_tmp2) ? var : ProString(splt).setSource(var));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case E_MEMBER:
|
case E_MEMBER:
|
||||||
@@ -761,7 +766,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
|
|||||||
} else {
|
} else {
|
||||||
QRegExp regx(args.at(1).toQString());
|
QRegExp regx(args.at(1).toQString());
|
||||||
int t = 0;
|
int t = 0;
|
||||||
foreach (const ProString &val, values(map(args.at(0)))) {
|
const auto vals = values(map(args.at(0)));
|
||||||
|
for (const ProString &val : vals) {
|
||||||
if (regx.indexIn(val.toQString(m_tmp[t])) != -1)
|
if (regx.indexIn(val.toQString(m_tmp[t])) != -1)
|
||||||
ret += val;
|
ret += val;
|
||||||
t ^= 1;
|
t ^= 1;
|
||||||
@@ -958,7 +964,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
|
|||||||
} else {
|
} else {
|
||||||
const QRegExp before(args.at(1).toQString());
|
const QRegExp before(args.at(1).toQString());
|
||||||
const QString &after(args.at(2).toQString(m_tmp2));
|
const QString &after(args.at(2).toQString(m_tmp2));
|
||||||
foreach (const ProString &val, values(map(args.at(0)))) {
|
const auto vals = values(map(args.at(0)));
|
||||||
|
for (const ProString &val : vals) {
|
||||||
QString rstr = val.toQString(m_tmp1);
|
QString rstr = val.toQString(m_tmp1);
|
||||||
QString copy = rstr; // Force a detach on modify
|
QString copy = rstr; // Force a detach on modify
|
||||||
rstr.replace(before, after);
|
rstr.replace(before, after);
|
||||||
@@ -1191,7 +1198,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
|
|||||||
regx.setPattern(copy);
|
regx.setPattern(copy);
|
||||||
}
|
}
|
||||||
int t = 0;
|
int t = 0;
|
||||||
foreach (const ProString &s, vars.value(map(args.at(1)))) {
|
const auto strings = vars.value(map(args.at(1)));
|
||||||
|
for (const ProString &s : strings) {
|
||||||
if ((!regx.isEmpty() && regx.exactMatch(s.toQString(m_tmp[t]))) || s == qry)
|
if ((!regx.isEmpty() && regx.exactMatch(s.toQString(m_tmp[t]))) || s == qry)
|
||||||
return ReturnTrue;
|
return ReturnTrue;
|
||||||
t ^= 1;
|
t ^= 1;
|
||||||
@@ -1569,7 +1577,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
|
|||||||
if (!vals.isEmpty())
|
if (!vals.isEmpty())
|
||||||
contents = vals.join(QLatin1Char('\n')) + QLatin1Char('\n');
|
contents = vals.join(QLatin1Char('\n')) + QLatin1Char('\n');
|
||||||
if (args.count() >= 3) {
|
if (args.count() >= 3) {
|
||||||
foreach (const ProString &opt, split_value_list(args.at(2).toQString(m_tmp2))) {
|
const auto opts = split_value_list(args.at(2).toQString(m_tmp2));
|
||||||
|
for (const ProString &opt : opts) {
|
||||||
opt.toQString(m_tmp3);
|
opt.toQString(m_tmp3);
|
||||||
if (m_tmp3 == QLatin1String("append")) {
|
if (m_tmp3 == QLatin1String("append")) {
|
||||||
mode = QIODevice::Append;
|
mode = QIODevice::Append;
|
||||||
@@ -1641,7 +1650,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
|
|||||||
enum { CacheSet, CacheAdd, CacheSub } mode = CacheSet;
|
enum { CacheSet, CacheAdd, CacheSub } mode = CacheSet;
|
||||||
ProKey srcvar;
|
ProKey srcvar;
|
||||||
if (args.count() >= 2) {
|
if (args.count() >= 2) {
|
||||||
foreach (const ProString &opt, split_value_list(args.at(1).toQString(m_tmp2))) {
|
const auto opts = split_value_list(args.at(1).toQString(m_tmp2));
|
||||||
|
for (const ProString &opt : opts) {
|
||||||
opt.toQString(m_tmp3);
|
opt.toQString(m_tmp3);
|
||||||
if (m_tmp3 == QLatin1String("transient")) {
|
if (m_tmp3 == QLatin1String("transient")) {
|
||||||
persist = false;
|
persist = false;
|
||||||
|
@@ -984,7 +984,8 @@ static ProString msvcArchitecture(const QString &vcInstallDir, const QString &pa
|
|||||||
QString vcBinDir = vcInstallDir;
|
QString vcBinDir = vcInstallDir;
|
||||||
if (vcBinDir.endsWith(QLatin1Char('\\')))
|
if (vcBinDir.endsWith(QLatin1Char('\\')))
|
||||||
vcBinDir.chop(1);
|
vcBinDir.chop(1);
|
||||||
foreach (const QString &dir, pathVar.split(QLatin1Char(';'))) {
|
const auto dirs = pathVar.split(QLatin1Char(';'));
|
||||||
|
for (const QString &dir : dirs) {
|
||||||
if (!dir.startsWith(vcBinDir, Qt::CaseInsensitive))
|
if (!dir.startsWith(vcBinDir, Qt::CaseInsensitive))
|
||||||
continue;
|
continue;
|
||||||
const ProString arch = msvcBinDirToQMakeArch(dir.mid(vcBinDir.length() + 1));
|
const ProString arch = msvcBinDirToQMakeArch(dir.mid(vcBinDir.length() + 1));
|
||||||
@@ -1458,7 +1459,8 @@ void QMakeEvaluator::updateMkspecPaths()
|
|||||||
QStringList ret;
|
QStringList ret;
|
||||||
const QString concat = QLatin1String("/mkspecs");
|
const QString concat = QLatin1String("/mkspecs");
|
||||||
|
|
||||||
foreach (const QString &it, m_option->getPathListEnv(QLatin1String("QMAKEPATH")))
|
const auto paths = m_option->getPathListEnv(QLatin1String("QMAKEPATH"));
|
||||||
|
for (const QString &it : paths)
|
||||||
ret << it + concat;
|
ret << it + concat;
|
||||||
|
|
||||||
foreach (const QString &it, m_qmakepath)
|
foreach (const QString &it, m_qmakepath)
|
||||||
@@ -1498,7 +1500,8 @@ void QMakeEvaluator::updateFeaturePaths()
|
|||||||
feature_bases << m_sourceRoot;
|
feature_bases << m_sourceRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (const QString &item, m_option->getPathListEnv(QLatin1String("QMAKEPATH")))
|
const auto items = m_option->getPathListEnv(QLatin1String("QMAKEPATH"));
|
||||||
|
for (const QString &item : items)
|
||||||
feature_bases << (item + mkspecs_concat);
|
feature_bases << (item + mkspecs_concat);
|
||||||
|
|
||||||
foreach (const QString &item, m_qmakepath)
|
foreach (const QString &item, m_qmakepath)
|
||||||
@@ -1524,7 +1527,8 @@ void QMakeEvaluator::updateFeaturePaths()
|
|||||||
feature_bases << (m_option->propertyValue(ProKey("QT_HOST_DATA/src")) + mkspecs_concat);
|
feature_bases << (m_option->propertyValue(ProKey("QT_HOST_DATA/src")) + mkspecs_concat);
|
||||||
|
|
||||||
foreach (const QString &fb, feature_bases) {
|
foreach (const QString &fb, feature_bases) {
|
||||||
foreach (const ProString &sfx, values(ProKey("QMAKE_PLATFORM")))
|
const auto sfxs = values(ProKey("QMAKE_PLATFORM"));
|
||||||
|
for (const ProString &sfx : sfxs)
|
||||||
feature_roots << (fb + features_concat + sfx + QLatin1Char('/'));
|
feature_roots << (fb + features_concat + sfx + QLatin1Char('/'));
|
||||||
feature_roots << (fb + features_concat);
|
feature_roots << (fb + features_concat);
|
||||||
}
|
}
|
||||||
@@ -1597,7 +1601,8 @@ bool QMakeEvaluator::isActiveConfig(const QString &config, bool regex)
|
|||||||
|
|
||||||
// CONFIG variable
|
// CONFIG variable
|
||||||
int t = 0;
|
int t = 0;
|
||||||
foreach (const ProString &configValue, values(statics.strCONFIG)) {
|
const auto configValues = values(statics.strCONFIG);
|
||||||
|
for (const ProString &configValue : configValues) {
|
||||||
if (re.exactMatch(configValue.toQString(m_tmp[t])))
|
if (re.exactMatch(configValue.toQString(m_tmp[t])))
|
||||||
return true;
|
return true;
|
||||||
t ^= 1;
|
t ^= 1;
|
||||||
@@ -2016,7 +2021,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFileInto(
|
|||||||
*values = visitor.m_valuemapStack.top();
|
*values = visitor.m_valuemapStack.top();
|
||||||
ProKey qiif("QMAKE_INTERNAL_INCLUDED_FILES");
|
ProKey qiif("QMAKE_INTERNAL_INCLUDED_FILES");
|
||||||
ProStringList &iif = m_valuemapStack.first()[qiif];
|
ProStringList &iif = m_valuemapStack.first()[qiif];
|
||||||
foreach (const ProString &ifn, values->value(qiif))
|
const auto ifns = values->value(qiif);
|
||||||
|
for (const ProString &ifn : ifns)
|
||||||
if (!iif.contains(ifn))
|
if (!iif.contains(ifn))
|
||||||
iif << ifn;
|
iif << ifn;
|
||||||
return ReturnTrue;
|
return ReturnTrue;
|
||||||
|
@@ -313,7 +313,8 @@ bool QMakeGlobals::initProperties()
|
|||||||
QT_PCLOSE(proc);
|
QT_PCLOSE(proc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
foreach (QByteArray line, data.split('\n')) {
|
const auto lines = data.split('\n');
|
||||||
|
for (QByteArray line : lines) {
|
||||||
int off = line.indexOf(':');
|
int off = line.indexOf(':');
|
||||||
if (off < 0) // huh?
|
if (off < 0) // huh?
|
||||||
continue;
|
continue;
|
||||||
|
Reference in New Issue
Block a user