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>
This commit is contained in:
parent
3f3140d38a
commit
8d7e913248
@ -1167,7 +1167,8 @@ void VcprojGenerator::initLinkerTool()
|
||||
|
||||
static const char * const lflags[] = { "QMAKE_LIBS", "QMAKE_LIBS_PRIVATE", 0 };
|
||||
for (int i = 0; lflags[i]; i++) {
|
||||
foreach (const ProString &lib, fixLibFlags(lflags[i])) {
|
||||
const auto libs = fixLibFlags(lflags[i]);
|
||||
for (const ProString &lib : libs) {
|
||||
if (lib.startsWith("/LIBPATH:"))
|
||||
conf.linker.AdditionalLibraryDirectories << lib.mid(9).toQString();
|
||||
else
|
||||
|
@ -487,14 +487,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));
|
||||
}
|
||||
@ -523,7 +524,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();
|
||||
@ -612,9 +614,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:
|
||||
@ -755,7 +760,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;
|
||||
@ -952,7 +958,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);
|
||||
@ -1181,7 +1188,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;
|
||||
@ -1553,7 +1561,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;
|
||||
@ -1625,7 +1634,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;
|
||||
|
@ -973,7 +973,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));
|
||||
@ -1447,7 +1448,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)
|
||||
@ -1487,7 +1489,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)
|
||||
@ -1513,7 +1516,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);
|
||||
}
|
||||
@ -1586,7 +1590,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;
|
||||
@ -1969,7 +1974,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;
|
||||
|
@ -314,7 +314,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;
|
||||
|
@ -139,7 +139,8 @@ QMakeProperty::exec()
|
||||
if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
|
||||
if(Option::prop::properties.isEmpty()) {
|
||||
initSettings();
|
||||
foreach (const QString &key, settings->childKeys()) {
|
||||
const auto keys = settings->childKeys();
|
||||
for (const QString &key : keys) {
|
||||
QString val = settings->value(key).toString();
|
||||
fprintf(stdout, "%s:%s\n", qPrintable(key), qPrintable(val));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user