QtCore: eradicate all Q_FOREACH loops [io]
Saves more than 1KiB in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I1a974e903bc8352af800fa26edae0194c1e51705 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5170c0416b
commit
194e158beb
@ -261,7 +261,7 @@ static QString selectionHelper(const QString &path, const QString &fileName, con
|
|||||||
*/
|
*/
|
||||||
Q_ASSERT(path.isEmpty() || path.endsWith(QLatin1Char('/')));
|
Q_ASSERT(path.isEmpty() || path.endsWith(QLatin1Char('/')));
|
||||||
|
|
||||||
foreach (const QString &s, selectors) {
|
for (const QString &s : selectors) {
|
||||||
QString prospectiveBase = path + QLatin1Char(selectorIndicator) + s + QLatin1Char('/');
|
QString prospectiveBase = path + QLatin1Char(selectorIndicator) + s + QLatin1Char('/');
|
||||||
QStringList remainingSelectors = selectors;
|
QStringList remainingSelectors = selectors;
|
||||||
remainingSelectors.removeAll(s);
|
remainingSelectors.removeAll(s);
|
||||||
|
@ -246,7 +246,7 @@ QInotifyFileSystemWatcherEngine::QInotifyFileSystemWatcherEngine(int fd, QObject
|
|||||||
QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine()
|
QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine()
|
||||||
{
|
{
|
||||||
notifier.setEnabled(false);
|
notifier.setEnabled(false);
|
||||||
foreach (int id, pathToID)
|
for (int id : qAsConst(pathToID))
|
||||||
inotify_rm_watch(inotifyFd, id < 0 ? -id : id);
|
inotify_rm_watch(inotifyFd, id < 0 ? -id : id);
|
||||||
|
|
||||||
::close(inotifyFd);
|
::close(inotifyFd);
|
||||||
|
@ -82,7 +82,7 @@ QKqueueFileSystemWatcherEngine::~QKqueueFileSystemWatcherEngine()
|
|||||||
notifier.setEnabled(false);
|
notifier.setEnabled(false);
|
||||||
close(kqfd);
|
close(kqfd);
|
||||||
|
|
||||||
foreach (int id, pathToID)
|
for (int id : qAsConst(pathToID))
|
||||||
::close(id < 0 ? -id : id);
|
::close(id < 0 ? -id : id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths,
|
|||||||
|
|
||||||
// now look for a thread to insert
|
// now look for a thread to insert
|
||||||
bool found = false;
|
bool found = false;
|
||||||
foreach(QWindowsFileSystemWatcherEngineThread *thread, threads) {
|
for (QWindowsFileSystemWatcherEngineThread *thread : qAsConst(threads)) {
|
||||||
QMutexLocker(&(thread->mutex));
|
QMutexLocker(&(thread->mutex));
|
||||||
if (thread->handles.count() < MAXIMUM_WAIT_OBJECTS) {
|
if (thread->handles.count() < MAXIMUM_WAIT_OBJECTS) {
|
||||||
DEBUG() << "Added handle" << handle.handle << "for" << absolutePath << "to watch" << fileInfo.absoluteFilePath()
|
DEBUG() << "Added handle" << handle.handle << "for" << absolutePath << "to watch" << fileInfo.absoluteFilePath()
|
||||||
@ -311,7 +311,7 @@ QWindowsFileSystemWatcherEngineThread::~QWindowsFileSystemWatcherEngineThread()
|
|||||||
CloseHandle(handles.at(0));
|
CloseHandle(handles.at(0));
|
||||||
handles[0] = INVALID_HANDLE_VALUE;
|
handles[0] = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
foreach (HANDLE h, handles) {
|
for (HANDLE h : qAsConst(handles)) {
|
||||||
if (h == INVALID_HANDLE_VALUE)
|
if (h == INVALID_HANDLE_VALUE)
|
||||||
continue;
|
continue;
|
||||||
FindCloseChangeNotification(h);
|
FindCloseChangeNotification(h);
|
||||||
@ -323,7 +323,7 @@ static inline QString msgFindNextFailed(const QWindowsFileSystemWatcherEngineThr
|
|||||||
QString result;
|
QString result;
|
||||||
QTextStream str(&result);
|
QTextStream str(&result);
|
||||||
str << "QFileSystemWatcher: FindNextChangeNotification failed for";
|
str << "QFileSystemWatcher: FindNextChangeNotification failed for";
|
||||||
foreach (const QWindowsFileSystemWatcherEngine::PathInfo &pathInfo, pathInfos)
|
for (const QWindowsFileSystemWatcherEngine::PathInfo &pathInfo : pathInfos)
|
||||||
str << " \"" << QDir::toNativeSeparators(pathInfo.absolutePath) << '"';
|
str << " \"" << QDir::toNativeSeparators(pathInfo.absolutePath) << '"';
|
||||||
str << ' ';
|
str << ' ';
|
||||||
return result;
|
return result;
|
||||||
|
@ -400,7 +400,7 @@ QLoggingRegistry *QLoggingRegistry::instance()
|
|||||||
*/
|
*/
|
||||||
void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
|
void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
|
||||||
{
|
{
|
||||||
QLoggingRegistry *reg = QLoggingRegistry::instance();
|
const QLoggingRegistry *reg = QLoggingRegistry::instance();
|
||||||
Q_ASSERT(reg->categories.contains(cat));
|
Q_ASSERT(reg->categories.contains(cat));
|
||||||
QtMsgType enableForLevel = reg->categories.value(cat);
|
QtMsgType enableForLevel = reg->categories.value(cat);
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString categoryName = QLatin1String(cat->categoryName());
|
QString categoryName = QLatin1String(cat->categoryName());
|
||||||
foreach (const QLoggingRule &item, reg->rules) {
|
for (const QLoggingRule &item : reg->rules) {
|
||||||
int filterpass = item.pass(categoryName, QtDebugMsg);
|
int filterpass = item.pass(categoryName, QtDebugMsg);
|
||||||
if (filterpass != 0)
|
if (filterpass != 0)
|
||||||
debug = (filterpass > 0);
|
debug = (filterpass > 0);
|
||||||
|
@ -533,10 +533,10 @@ QStringList QWinRTSettingsPrivate::children(const QString &uKey, ChildSpec spec)
|
|||||||
const QStringList subContainerList = subContainerNames(container.Get(), spec == AllKeys);
|
const QStringList subContainerList = subContainerNames(container.Get(), spec == AllKeys);
|
||||||
|
|
||||||
if (spec == AllKeys) {
|
if (spec == AllKeys) {
|
||||||
foreach (const QString &item, subContainerList) {
|
for (const QString &item : subContainerList) {
|
||||||
const QString subChildren = uKey.isEmpty() ? item : (uKey + QLatin1Char('/') + item);
|
const QString subChildren = uKey.isEmpty() ? item : (uKey + QLatin1Char('/') + item);
|
||||||
const QStringList subResult = children(subChildren, ChildKeys);
|
const QStringList subResult = children(subChildren, ChildKeys);
|
||||||
foreach (const QString &subItem, subResult)
|
for (const QString &subItem : subResult)
|
||||||
result += item + QLatin1Char('/') + subItem;
|
result += item + QLatin1Char('/') + subItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -644,7 +644,7 @@ IApplicationDataContainer *QWinRTSettingsPrivate::getContainer(IApplicationDataC
|
|||||||
return current;
|
return current;
|
||||||
const QStringList groupPath = group.split(QLatin1Char('/'), QString::SkipEmptyParts);
|
const QStringList groupPath = group.split(QLatin1Char('/'), QString::SkipEmptyParts);
|
||||||
|
|
||||||
foreach (const QString &subGroup, groupPath) {
|
for (const QString &subGroup : groupPath) {
|
||||||
ComPtr<IApplicationDataContainer> sub = subContainer(current, subGroup);
|
ComPtr<IApplicationDataContainer> sub = subContainer(current, subGroup);
|
||||||
if (!sub && create)
|
if (!sub && create)
|
||||||
sub = createSubContainer(current, subGroup);
|
sub = createSubContainer(current, subGroup);
|
||||||
|
@ -443,7 +443,7 @@ static inline QString searchExecutable(const QStringList &searchPaths,
|
|||||||
const QString &executableName)
|
const QString &executableName)
|
||||||
{
|
{
|
||||||
const QDir currentDir = QDir::current();
|
const QDir currentDir = QDir::current();
|
||||||
foreach (const QString &searchPath, searchPaths) {
|
for (const QString &searchPath : searchPaths) {
|
||||||
const QString candidate = currentDir.absoluteFilePath(searchPath + QLatin1Char('/') + executableName);
|
const QString candidate = currentDir.absoluteFilePath(searchPath + QLatin1Char('/') + executableName);
|
||||||
const QString absPath = checkExecutable(candidate);
|
const QString absPath = checkExecutable(candidate);
|
||||||
if (!absPath.isEmpty())
|
if (!absPath.isEmpty())
|
||||||
@ -462,9 +462,9 @@ static inline QString
|
|||||||
const QStringList &suffixes)
|
const QStringList &suffixes)
|
||||||
{
|
{
|
||||||
const QDir currentDir = QDir::current();
|
const QDir currentDir = QDir::current();
|
||||||
foreach (const QString &searchPath, searchPaths) {
|
for (const QString &searchPath : searchPaths) {
|
||||||
const QString candidateRoot = currentDir.absoluteFilePath(searchPath + QLatin1Char('/') + executableName);
|
const QString candidateRoot = currentDir.absoluteFilePath(searchPath + QLatin1Char('/') + executableName);
|
||||||
foreach (const QString &suffix, suffixes) {
|
for (const QString &suffix : suffixes) {
|
||||||
const QString absPath = checkExecutable(candidateRoot + suffix);
|
const QString absPath = checkExecutable(candidateRoot + suffix);
|
||||||
if (!absPath.isEmpty())
|
if (!absPath.isEmpty())
|
||||||
return absPath;
|
return absPath;
|
||||||
@ -505,7 +505,7 @@ QString QStandardPaths::findExecutable(const QString &executableName, const QStr
|
|||||||
// Remove trailing slashes, which occur on Windows.
|
// Remove trailing slashes, which occur on Windows.
|
||||||
const QStringList rawPaths = QString::fromLocal8Bit(pEnv.constData()).split(QDir::listSeparator(), QString::SkipEmptyParts);
|
const QStringList rawPaths = QString::fromLocal8Bit(pEnv.constData()).split(QDir::listSeparator(), QString::SkipEmptyParts);
|
||||||
searchPaths.reserve(rawPaths.size());
|
searchPaths.reserve(rawPaths.size());
|
||||||
foreach (const QString &rawPath, rawPaths) {
|
for (const QString &rawPath : rawPaths) {
|
||||||
QString cleanPath = QDir::cleanPath(rawPath);
|
QString cleanPath = QDir::cleanPath(rawPath);
|
||||||
if (cleanPath.size() > 1 && cleanPath.endsWith(QLatin1Char('/')))
|
if (cleanPath.size() > 1 && cleanPath.endsWith(QLatin1Char('/')))
|
||||||
cleanPath.truncate(cleanPath.size() - 1);
|
cleanPath.truncate(cleanPath.size() - 1);
|
||||||
|
@ -4062,7 +4062,7 @@ QStringList QUrl::toStringList(const QList<QUrl> &urls, FormattingOptions option
|
|||||||
{
|
{
|
||||||
QStringList lst;
|
QStringList lst;
|
||||||
lst.reserve(urls.size());
|
lst.reserve(urls.size());
|
||||||
foreach (const QUrl &url, urls)
|
for (const QUrl &url : urls)
|
||||||
lst.append(url.toString(options));
|
lst.append(url.toString(options));
|
||||||
return lst;
|
return lst;
|
||||||
|
|
||||||
@ -4078,9 +4078,8 @@ QList<QUrl> QUrl::fromStringList(const QStringList &urls, ParsingMode mode)
|
|||||||
{
|
{
|
||||||
QList<QUrl> lst;
|
QList<QUrl> lst;
|
||||||
lst.reserve(urls.size());
|
lst.reserve(urls.size());
|
||||||
foreach (const QString &str, urls) {
|
for (const QString &str : urls)
|
||||||
lst.append(QUrl(str, mode));
|
lst.append(QUrl(str, mode));
|
||||||
}
|
|
||||||
return lst;
|
return lst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,10 +154,10 @@ inline QList<QPair<QByteArray, QByteArray> > QUrl::encodedQueryItems() const
|
|||||||
}
|
}
|
||||||
inline QList<QByteArray> QUrl::allEncodedQueryItemValues(const QByteArray &key) const
|
inline QList<QByteArray> QUrl::allEncodedQueryItemValues(const QByteArray &key) const
|
||||||
{
|
{
|
||||||
QStringList items = QUrlQuery(*this).allQueryItemValues(fromEncodedComponent_helper(key), QUrl::FullyEncoded);
|
const QStringList items = QUrlQuery(*this).allQueryItemValues(fromEncodedComponent_helper(key), QUrl::FullyEncoded);
|
||||||
QList<QByteArray> result;
|
QList<QByteArray> result;
|
||||||
result.reserve(items.size());
|
result.reserve(items.size());
|
||||||
Q_FOREACH (const QString &item, items)
|
for (const QString &item : items)
|
||||||
result << item.toLatin1();
|
result << item.toLatin1();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user