QtCore: eradicate all Q_FOREACH loops [tools]

Saves just under 5.5KiB in text size on optimized GCC 4.9 Linux
AMD64 builds.

Change-Id: I6d868a7d2e469cf0564127b0e66cd7b272a0c9cd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Marc Mutz 2015-12-23 00:15:30 +01:00
parent 5feebcc973
commit a3ce123549
6 changed files with 24 additions and 25 deletions

View File

@ -348,10 +348,10 @@ void QCommandLineParser::setOptionsAfterPositionalArgumentsMode(QCommandLinePars
*/
bool QCommandLineParser::addOption(const QCommandLineOption &option)
{
QStringList optionNames = option.names();
const QStringList optionNames = option.names();
if (!optionNames.isEmpty()) {
foreach (const QString &name, optionNames) {
for (const QString &name : optionNames) {
if (d->nameHash.contains(name))
return false;
}
@ -359,7 +359,7 @@ bool QCommandLineParser::addOption(const QCommandLineOption &option)
d->commandLineOptionList.append(option);
const int offset = d->commandLineOptionList.size() - 1;
foreach (const QString &name, optionNames)
for (const QString &name : optionNames)
d->nameHash.insert(name, offset);
return true;
@ -791,7 +791,7 @@ bool QCommandLineParser::isSet(const QString &name) const
if (d->optionNames.contains(name))
return true;
const QStringList aliases = d->aliases(name);
foreach (const QString &optionName, d->optionNames) {
for (const QString &optionName : qAsConst(d->optionNames)) {
if (aliases.contains(optionName))
return true;
}
@ -1073,7 +1073,7 @@ QString QCommandLineParserPrivate::helpText() const
usage += QCoreApplication::instance()->arguments().constFirst(); // executable name
if (!commandLineOptionList.isEmpty())
usage += QLatin1Char(' ') + QCommandLineParser::tr("[options]");
foreach (const PositionalArgumentDefinition &arg, positionalArgumentDefinitions)
for (const PositionalArgumentDefinition &arg : positionalArgumentDefinitions)
usage += QLatin1Char(' ') + arg.syntax;
text += QCommandLineParser::tr("Usage: %1").arg(usage) + nl;
if (!description.isEmpty())
@ -1084,12 +1084,12 @@ QString QCommandLineParserPrivate::helpText() const
QStringList optionNameList;
optionNameList.reserve(commandLineOptionList.size());
int longestOptionNameString = 0;
foreach (const QCommandLineOption &option, commandLineOptionList) {
for (const QCommandLineOption &option : commandLineOptionList) {
if (option.isHidden())
continue;
const QStringList optionNames = option.names();
QString optionNamesString;
foreach (const QString &optionName, optionNames) {
for (const QString &optionName : optionNames) {
const int numDashes = optionName.length() == 1 ? 1 : 2;
optionNamesString += QLatin1String("--", numDashes) + optionName + QLatin1String(", ");
}
@ -1103,8 +1103,7 @@ QString QCommandLineParserPrivate::helpText() const
}
++longestOptionNameString;
auto optionNameIterator = optionNameList.cbegin();
for (int i = 0; i < commandLineOptionList.count(); ++i) {
const QCommandLineOption &option = commandLineOptionList.at(i);
for (const QCommandLineOption &option : commandLineOptionList) {
if (option.isHidden())
continue;
text += wrapText(*optionNameIterator, longestOptionNameString, option.description());
@ -1114,9 +1113,8 @@ QString QCommandLineParserPrivate::helpText() const
if (!commandLineOptionList.isEmpty())
text += nl;
text += QCommandLineParser::tr("Arguments:") + nl;
foreach (const PositionalArgumentDefinition &arg, positionalArgumentDefinitions) {
for (const PositionalArgumentDefinition &arg : positionalArgumentDefinitions)
text += wrapText(arg.name, longestOptionNameString, arg.description);
}
}
return text;
}

View File

@ -678,7 +678,7 @@ QVariant QSystemLocalePrivate::uiLanguages()
bool found = false;
// Since ApplicationLanguages:::Languages uses long names, we compare the "pre-dash" part of
// the language and filter it out, if it is already covered by a more specialized form.
foreach (const QString &lang, result) {
for (const QString &lang : qAsConst(result)) {
int dashIndex = lang.indexOf('-');
// There will not be any long name after the first short name was found, so we can stop.
if (dashIndex == -1)

View File

@ -3589,7 +3589,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after)
lastEnd = 0;
// add the after string, with replacements for the backreferences
foreach (const QStringCapture &backReference, backReferences) {
for (const QStringCapture &backReference : qAsConst(backReferences)) {
// part of "after" before the backreference
len = backReference.pos - lastEnd;
if (len > 0) {
@ -3627,7 +3627,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after)
resize(newLength);
int i = 0;
QChar *uc = data();
foreach (const QStringRef &chunk, chunks) {
for (const QStringRef &chunk : qAsConst(chunks)) {
int len = chunk.length();
memcpy(uc + i, chunk.unicode(), len * sizeof(QChar));
i += len;

View File

@ -765,10 +765,10 @@ QTimeZone::OffsetDataList QTimeZone::transitions(const QDateTime &fromDateTime,
{
OffsetDataList list;
if (hasTransitions()) {
QTimeZonePrivate::DataList plist = d->transitions(fromDateTime.toMSecsSinceEpoch(),
toDateTime.toMSecsSinceEpoch());
const QTimeZonePrivate::DataList plist = d->transitions(fromDateTime.toMSecsSinceEpoch(),
toDateTime.toMSecsSinceEpoch());
list.reserve(plist.count());
foreach (const QTimeZonePrivate::Data &pdata, plist)
for (const QTimeZonePrivate::Data &pdata : plist)
list.append(d->toOffsetData(pdata));
}
return list;

View File

@ -255,7 +255,7 @@ static QMap<int, QByteArray> parseTzAbbreviations(QDataStream &ds, int tzh_charc
return map;
}
// Then extract all the substrings pointed to by types
foreach (const QTzType &type, types) {
for (const QTzType &type : types) {
QByteArray abbrev;
for (int i = type.tz_abbrind; input.at(i) != '\0'; ++i)
abbrev.append(input.at(i));
@ -629,7 +629,7 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
// Offsets are stored as total offset, want to know separate UTC and DST offsets
// so find the first non-dst transition to use as base UTC Offset
int utcOffset = 0;
foreach (const QTzTransition &tran, tranList) {
for (const QTzTransition &tran : qAsConst(tranList)) {
if (!typeList.at(tran.tz_typeind).tz_isdst) {
utcOffset = typeList.at(tran.tz_typeind).tz_gmtoff;
break;
@ -638,7 +638,7 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
// Now for each transition time calculate our rule and save them
m_tranTimes.reserve(tranList.count());
foreach (const QTzTransition &tz_tran, tranList) {
for (const QTzTransition &tz_tran : qAsConst(tranList)) {
QTzTransitionTime tran;
QTzTransitionRule rule;
const QTzType tz_type = typeList.at(tz_tran.tz_typeind);
@ -790,7 +790,7 @@ int QTzTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const
bool QTzTimeZonePrivate::hasDaylightTime() const
{
// TODO Perhaps cache as frequently accessed?
foreach (const QTzTransitionRule &rule, m_tranRules) {
for (const QTzTransitionRule &rule : m_tranRules) {
if (rule.dstOffset != 0)
return true;
}

View File

@ -237,7 +237,8 @@ static QByteArray windowsSystemZoneId()
TIME_ZONE_INFORMATION sysTzi;
GetTimeZoneInformation(&sysTzi);
bool ok = false;
foreach (const QByteArray &winId, availableWindowsIds()) {
const auto winIds = availableWindowsIds();
for (const QByteArray &winId : winIds) {
if (equalTzi(getRegistryTzi(winId, &ok), sysTzi))
return winId;
}
@ -506,7 +507,7 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons
bool QWinTimeZonePrivate::hasTransitions() const
{
foreach (const QWinTransitionRule &rule, m_tranRules) {
for (const QWinTransitionRule &rule : m_tranRules) {
if (rule.standardTimeRule.wMonth > 0 && rule.daylightTimeRule.wMonth > 0)
return true;
}
@ -637,9 +638,9 @@ QByteArray QWinTimeZonePrivate::systemTimeZoneId() const
QList<QByteArray> QWinTimeZonePrivate::availableTimeZoneIds() const
{
QList<QByteArray> result;
foreach (const QByteArray &winId, availableWindowsIds()) {
const auto winIds = availableWindowsIds();
for (const QByteArray &winId : winIds)
result += windowsIdToIanaIds(winId);
}
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
return result;