Remove the last uses of Java-style iterators in QtCore
They are going to be deprecated. Add a strategic break. This was a pre-existing problem: the comment claims that h is invalid (though I personally don't see it), but then goes on to check the loop condition (which, in the mutable Java iterator case, involves calling h.cend()). We now cache the end iterator, so if there ever was a problem, it's probably a lesser one now, but it's still not kosher, and a debug version of QHash would find it, so break out explicitly. Saves ~200b in text size on optimized GCC 9.1 Linux AMD64 builds, ie. ~100b per loop. Change-Id: I7684485b55fb23a8cf882f89621ebb75a0e607b5 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
ac608b7bd2
commit
18e7e82d3f
@ -110,33 +110,32 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path
|
|||||||
|
|
||||||
void QPollingFileSystemWatcherEngine::timeout()
|
void QPollingFileSystemWatcherEngine::timeout()
|
||||||
{
|
{
|
||||||
QMutableHashIterator<QString, FileInfo> fit(files);
|
for (auto it = files.begin(), end = files.end(); it != end; /*erasing*/) {
|
||||||
while (fit.hasNext()) {
|
auto x = it++;
|
||||||
QHash<QString, FileInfo>::iterator x = fit.next();
|
|
||||||
QString path = x.key();
|
QString path = x.key();
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
fit.remove();
|
files.erase(x);
|
||||||
emit fileChanged(path, true);
|
emit fileChanged(path, true);
|
||||||
} else if (x.value() != fi) {
|
} else if (x.value() != fi) {
|
||||||
x.value() = fi;
|
x.value() = fi;
|
||||||
emit fileChanged(path, false);
|
emit fileChanged(path, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QMutableHashIterator<QString, FileInfo> dit(directories);
|
|
||||||
while (dit.hasNext()) {
|
for (auto it = directories.begin(), end = directories.end(); it != end; /*erasing*/) {
|
||||||
QHash<QString, FileInfo>::iterator x = dit.next();
|
auto x = it++;
|
||||||
QString path = x.key();
|
QString path = x.key();
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
if (!path.endsWith(QLatin1Char('/')))
|
if (!path.endsWith(QLatin1Char('/')))
|
||||||
fi = QFileInfo(path + QLatin1Char('/'));
|
fi = QFileInfo(path + QLatin1Char('/'));
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
dit.remove();
|
directories.erase(x);
|
||||||
emit directoryChanged(path, true);
|
emit directoryChanged(path, true);
|
||||||
} else if (x.value() != fi) {
|
} else if (x.value() != fi) {
|
||||||
fi.refresh();
|
fi.refresh();
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
dit.remove();
|
directories.erase(x);
|
||||||
emit directoryChanged(path, true);
|
emit directoryChanged(path, true);
|
||||||
} else {
|
} else {
|
||||||
x.value() = fi;
|
x.value() = fi;
|
||||||
|
@ -695,9 +695,8 @@ void QWindowsFileSystemWatcherEngineThread::run()
|
|||||||
|
|
||||||
qErrnoWarning(error, "%ls", qUtf16Printable(msgFindNextFailed(h)));
|
qErrnoWarning(error, "%ls", qUtf16Printable(msgFindNextFailed(h)));
|
||||||
}
|
}
|
||||||
QMutableHashIterator<QFileSystemWatcherPathKey, QWindowsFileSystemWatcherEngine::PathInfo> it(h);
|
for (auto it = h.begin(), end = h.end(); it != end; /*erasing*/ ) {
|
||||||
while (it.hasNext()) {
|
auto x = it++;
|
||||||
QWindowsFileSystemWatcherEngineThread::PathInfoHash::iterator x = it.next();
|
|
||||||
QString absolutePath = x.value().absolutePath;
|
QString absolutePath = x.value().absolutePath;
|
||||||
QFileInfo fileInfo(x.value().path);
|
QFileInfo fileInfo(x.value().path);
|
||||||
DEBUG() << "checking" << x.key();
|
DEBUG() << "checking" << x.key();
|
||||||
@ -723,6 +722,7 @@ void QWindowsFileSystemWatcherEngineThread::run()
|
|||||||
|
|
||||||
handleForDir.remove(QFileSystemWatcherPathKey(absolutePath));
|
handleForDir.remove(QFileSystemWatcherPathKey(absolutePath));
|
||||||
// h is now invalid
|
// h is now invalid
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (x.value().isDir) {
|
} else if (x.value().isDir) {
|
||||||
DEBUG() << x.key() << "directory changed!";
|
DEBUG() << x.key() << "directory changed!";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user