Commit 1a4f0f1d authored by Marc Mutz's avatar Marc Mutz Committed by Oswald Buddenhagen

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: default avatarLars Knoll <lars.knoll@theqtcompany.com>
(cherry picked from qtbase/8d7e913248aa1cad23447668d98911bba01faf4b)
Reviewed-by: default avatarMarc Mutz <marc.mutz@kdab.com>
Reviewed-by: Jake Petroules's avatarJake Petroules <jake.petroules@qt.io>
parent ccdcbc55
......@@ -493,14 +493,15 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
}
}
if (!var.isEmpty()) {
const auto strings = values(map(var));
if (regexp) {
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);
ret << (rstr.isSharedWith(m_tmp1) ? str : ProString(rstr).setSource(str));
}
} else {
foreach (const ProString &str, values(map(var))) {
for (const ProString &str : strings) {
const QString &rstr = str.toQString(m_tmp1).section(sep, beg, end);
ret << (rstr.isSharedWith(m_tmp1) ? str : ProString(rstr).setSource(str));
}
......@@ -529,7 +530,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
bool leftalign = false;
enum { DefaultSign, PadSign, AlwaysSign } sign = DefaultSign;
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);
if (m_tmp3.startsWith(QLatin1String("ibase="))) {
ibase = m_tmp3.mid(6).toInt();
......@@ -618,9 +620,12 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
evalError(fL1S("split(var, sep) requires one or two arguments."));
} else {
const QString &sep = (args.count() == 2) ? args.at(1).toQString(m_tmp1) : statics.field_sep;
foreach (const ProString &var, values(map(args.at(0))))
foreach (const QString &splt, var.toQString(m_tmp2).split(sep))
const auto vars = values(map(args.at(0)));
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));
}
}
break;
case E_MEMBER:
......@@ -761,7 +766,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
} else {
QRegExp regx(args.at(1).toQString());
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)
ret += val;
t ^= 1;
......@@ -958,7 +964,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
} else {
const QRegExp before(args.at(1).toQString());
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 copy = rstr; // Force a detach on modify
rstr.replace(before, after);
......@@ -1191,7 +1198,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
regx.setPattern(copy);
}
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)
return ReturnTrue;
t ^= 1;
......@@ -1569,7 +1577,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
if (!vals.isEmpty())
contents = vals.join(QLatin1Char('\n')) + QLatin1Char('\n');
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);
if (m_tmp3 == QLatin1String("append")) {
mode = QIODevice::Append;
......@@ -1641,7 +1650,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
enum { CacheSet, CacheAdd, CacheSub } mode = CacheSet;
ProKey srcvar;
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);
if (m_tmp3 == QLatin1String("transient")) {
persist = false;
......
......@@ -984,7 +984,8 @@ static ProString msvcArchitecture(const QString &vcInstallDir, const QString &pa
QString vcBinDir = vcInstallDir;
if (vcBinDir.endsWith(QLatin1Char('\\')))
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))
continue;
const ProString arch = msvcBinDirToQMakeArch(dir.mid(vcBinDir.length() + 1));
......@@ -1458,7 +1459,8 @@ void QMakeEvaluator::updateMkspecPaths()
QStringList ret;
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;
foreach (const QString &it, m_qmakepath)
......@@ -1498,7 +1500,8 @@ void QMakeEvaluator::updateFeaturePaths()
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);
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);
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);
}
......@@ -1597,7 +1601,8 @@ bool QMakeEvaluator::isActiveConfig(const QString &config, bool regex)
// CONFIG variable
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])))
return true;
t ^= 1;
......@@ -2016,7 +2021,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFileInto(
*values = visitor.m_valuemapStack.top();
ProKey qiif("QMAKE_INTERNAL_INCLUDED_FILES");
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))
iif << ifn;
return ReturnTrue;
......
......@@ -313,7 +313,8 @@ bool QMakeGlobals::initProperties()
QT_PCLOSE(proc);
}
#endif
foreach (QByteArray line, data.split('\n')) {
const auto lines = data.split('\n');
for (QByteArray line : lines) {
int off = line.indexOf(':');
if (off < 0) // huh?
continue;
......
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