QtCore: eradicate all Q_FOREACH loops [mimetypes]
Saves just shy of 6KiB in text size on optimized GCC 4.9 Linux AMD64 builds, iow: ~0.1% of the total QtCore library size. Change-Id: I087e1e34a64944affb1211e16371e314012c4b2c Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
fd7861ac4b
commit
0ff221f522
@ -187,7 +187,7 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
|
||||
// "for glob_match in glob_matches:"
|
||||
// "if glob_match is subclass or equal to sniffed_type, use glob_match"
|
||||
const QString sniffedMime = candidateByData.name();
|
||||
foreach (const QString &m, candidatesByName) {
|
||||
for (const QString &m : qAsConst(candidatesByName)) {
|
||||
if (inherits(m, sniffedMime)) {
|
||||
// We have magic + pattern pointing to this, so it's a pretty good match
|
||||
*accuracyPtr = 100;
|
||||
@ -224,7 +224,8 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
|
||||
const QString current = toCheck.pop();
|
||||
if (current == resolvedParent)
|
||||
return true;
|
||||
foreach (const QString &par, provider()->parents(current))
|
||||
const auto parents = provider()->parents(current);
|
||||
for (const QString &par : parents)
|
||||
toCheck.push(par);
|
||||
}
|
||||
return false;
|
||||
@ -431,10 +432,10 @@ QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) co
|
||||
{
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
QStringList matches = d->mimeTypeForFileName(fileName);
|
||||
const QStringList matches = d->mimeTypeForFileName(fileName);
|
||||
QList<QMimeType> mimes;
|
||||
mimes.reserve(matches.count());
|
||||
foreach (const QString &mime, matches)
|
||||
for (const QString &mime : matches)
|
||||
mimes.append(d->mimeTypeForName(mime));
|
||||
return mimes;
|
||||
}
|
||||
|
@ -213,9 +213,8 @@ QStringList QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QString
|
||||
// (toLower because fast patterns are always case-insensitive and saved as lowercase)
|
||||
|
||||
const QStringList matchingMimeTypes = m_fastPatterns.value(simpleExtension);
|
||||
foreach (const QString &mime, matchingMimeTypes) {
|
||||
for (const QString &mime : matchingMimeTypes)
|
||||
result.addMatch(mime, 50, QLatin1String("*.") + simpleExtension);
|
||||
}
|
||||
// Can't return yet; *.tar.bz2 has to win over *.bz2, so we need the low-weight mimetypes anyway,
|
||||
// at least those with weight 50.
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ QList<QMimeMagicRule> QMimeMagicRuleMatcher::magicRules() const
|
||||
// Check for a match on contents of a file
|
||||
bool QMimeMagicRuleMatcher::matches(const QByteArray &data) const
|
||||
{
|
||||
foreach (const QMimeMagicRule &magicRule, m_list) {
|
||||
for (const QMimeMagicRule &magicRule : m_list) {
|
||||
if (magicRule.matches(data))
|
||||
return true;
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ void QMimeBinaryProvider::checkCache()
|
||||
// Then check if new cache files appeared
|
||||
const QStringList cacheFileNames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/mime.cache"));
|
||||
if (cacheFileNames != m_cacheFileNames) {
|
||||
foreach (const QString &cacheFileName, cacheFileNames) {
|
||||
for (const QString &cacheFileName : cacheFileNames) {
|
||||
CacheFile *cacheFile = m_cacheFiles.findCacheFile(cacheFileName);
|
||||
if (!cacheFile) {
|
||||
//qDebug() << "new file:" << cacheFileName;
|
||||
@ -287,7 +287,7 @@ QStringList QMimeBinaryProvider::findByFileName(const QString &fileName, QString
|
||||
const QString lowerFileName = fileName.toLower();
|
||||
QMimeGlobMatchResult result;
|
||||
// TODO this parses in the order (local, global). Check that it handles "NOGLOBS" correctly.
|
||||
foreach (CacheFile *cacheFile, m_cacheFiles) {
|
||||
for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
|
||||
matchGlobList(result, cacheFile, cacheFile->getUint32(PosLiteralListOffset), fileName);
|
||||
matchGlobList(result, cacheFile, cacheFile->getUint32(PosGlobListOffset), fileName);
|
||||
const int reverseSuffixTreeOffset = cacheFile->getUint32(PosReverseSuffixTreeOffset);
|
||||
@ -399,7 +399,7 @@ bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFi
|
||||
QMimeType QMimeBinaryProvider::findByMagic(const QByteArray &data, int *accuracyPtr)
|
||||
{
|
||||
checkCache();
|
||||
foreach (CacheFile *cacheFile, m_cacheFiles) {
|
||||
for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
|
||||
const int magicListOffset = cacheFile->getUint32(PosMagicListOffset);
|
||||
const int numMatches = cacheFile->getUint32(magicListOffset);
|
||||
//const int maxExtent = cacheFile->getUint32(magicListOffset + 4);
|
||||
@ -427,7 +427,7 @@ QStringList QMimeBinaryProvider::parents(const QString &mime)
|
||||
checkCache();
|
||||
const QByteArray mimeStr = mime.toLatin1();
|
||||
QStringList result;
|
||||
foreach (CacheFile *cacheFile, m_cacheFiles) {
|
||||
for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
|
||||
const int parentListOffset = cacheFile->getUint32(PosParentListOffset);
|
||||
const int numEntries = cacheFile->getUint32(parentListOffset);
|
||||
|
||||
@ -467,7 +467,7 @@ QString QMimeBinaryProvider::resolveAlias(const QString &name)
|
||||
{
|
||||
checkCache();
|
||||
const QByteArray input = name.toLatin1();
|
||||
foreach (CacheFile *cacheFile, m_cacheFiles) {
|
||||
for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
|
||||
const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset);
|
||||
const int numEntries = cacheFile->getUint32(aliasListOffset);
|
||||
int begin = 0;
|
||||
@ -498,7 +498,7 @@ QStringList QMimeBinaryProvider::listAliases(const QString &name)
|
||||
checkCache();
|
||||
QStringList result;
|
||||
const QByteArray input = name.toLatin1();
|
||||
foreach (CacheFile *cacheFile, m_cacheFiles) {
|
||||
for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
|
||||
const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset);
|
||||
const int numEntries = cacheFile->getUint32(aliasListOffset);
|
||||
for (int pos = 0; pos < numEntries; ++pos) {
|
||||
@ -524,7 +524,7 @@ void QMimeBinaryProvider::loadMimeTypeList()
|
||||
// Unfortunately mime.cache doesn't have a full list of all mimetypes.
|
||||
// So we have to parse the plain-text files called "types".
|
||||
const QStringList typesFilenames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/types"));
|
||||
foreach (const QString &typeFilename, typesFilenames) {
|
||||
for (const QString &typeFilename : typesFilenames) {
|
||||
QFile file(typeFilename);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
while (!file.atEnd()) {
|
||||
@ -677,7 +677,7 @@ void QMimeBinaryProvider::loadIcon(QMimeTypePrivate &data)
|
||||
{
|
||||
checkCache();
|
||||
const QByteArray inputMime = data.name.toLatin1();
|
||||
foreach (CacheFile *cacheFile, m_cacheFiles) {
|
||||
for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
|
||||
const QString icon = iconForMime(cacheFile, PosIconsListOffset, inputMime);
|
||||
if (!icon.isEmpty()) {
|
||||
data.iconName = icon;
|
||||
@ -690,7 +690,7 @@ void QMimeBinaryProvider::loadGenericIcon(QMimeTypePrivate &data)
|
||||
{
|
||||
checkCache();
|
||||
const QByteArray inputMime = data.name.toLatin1();
|
||||
foreach (CacheFile *cacheFile, m_cacheFiles) {
|
||||
for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
|
||||
const QString icon = iconForMime(cacheFile, PosGenericIconsListOffset, inputMime);
|
||||
if (!icon.isEmpty()) {
|
||||
data.genericIconName = icon;
|
||||
@ -733,7 +733,7 @@ QMimeType QMimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr
|
||||
|
||||
QString candidate;
|
||||
|
||||
foreach (const QMimeMagicRuleMatcher &matcher, m_magicMatchers) {
|
||||
for (const QMimeMagicRuleMatcher &matcher : qAsConst(m_magicMatchers)) {
|
||||
if (matcher.matches(data)) {
|
||||
const int priority = matcher.priority();
|
||||
if (priority > *accuracyPtr) {
|
||||
@ -753,7 +753,7 @@ void QMimeXMLProvider::ensureLoaded()
|
||||
|
||||
const QStringList packageDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/packages"), QStandardPaths::LocateDirectory);
|
||||
//qDebug() << "packageDirs=" << packageDirs;
|
||||
foreach (const QString &packageDir, packageDirs) {
|
||||
for (const QString &packageDir : packageDirs) {
|
||||
QDir dir(packageDir);
|
||||
const QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
|
||||
//qDebug() << static_cast<const void *>(this) << packageDir << files;
|
||||
@ -782,7 +782,7 @@ void QMimeXMLProvider::ensureLoaded()
|
||||
|
||||
//qDebug() << "Loading" << m_allFiles;
|
||||
|
||||
foreach (const QString &file, allFiles)
|
||||
for (const QString &file : qAsConst(allFiles))
|
||||
load(file);
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ QString QMimeType::comment() const
|
||||
QStringList languageList;
|
||||
languageList << QLocale::system().name();
|
||||
languageList << QLocale::system().uiLanguages();
|
||||
Q_FOREACH (const QString &language, languageList) {
|
||||
for (const QString &language : qAsConst(languageList)) {
|
||||
const QString lang = language == QLatin1String("C") ? QLatin1String("en_US") : language;
|
||||
const QString comm = d->localeComments.value(lang);
|
||||
if (!comm.isEmpty())
|
||||
@ -337,17 +337,16 @@ QStringList QMimeType::parentMimeTypes() const
|
||||
|
||||
static void collectParentMimeTypes(const QString &mime, QStringList &allParents)
|
||||
{
|
||||
QStringList parents = QMimeDatabasePrivate::instance()->provider()->parents(mime);
|
||||
foreach (const QString &parent, parents) {
|
||||
const QStringList parents = QMimeDatabasePrivate::instance()->provider()->parents(mime);
|
||||
for (const QString &parent : parents) {
|
||||
// I would use QSet, but since order matters I better not
|
||||
if (!allParents.contains(parent))
|
||||
allParents.append(parent);
|
||||
}
|
||||
// We want a breadth-first search, so that the least-specific parent (octet-stream) is last
|
||||
// This means iterating twice, unfortunately.
|
||||
foreach (const QString &parent, parents) {
|
||||
for (const QString &parent : parents)
|
||||
collectParentMimeTypes(parent, allParents);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -392,7 +391,7 @@ QStringList QMimeType::suffixes() const
|
||||
QMimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d);
|
||||
|
||||
QStringList result;
|
||||
foreach (const QString &pattern, d->globPatterns) {
|
||||
for (const QString &pattern : qAsConst(d->globPatterns)) {
|
||||
// Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP?
|
||||
if (pattern.startsWith(QLatin1String("*.")) &&
|
||||
pattern.length() > 2 &&
|
||||
|
Loading…
Reference in New Issue
Block a user