diff options
Diffstat (limited to 'src/corelib/io/qfilesystemwatcher_inotify.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_inotify.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 5fb5685f42..ca1f6cc359 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -422,16 +422,27 @@ void QInotifyFileSystemWatcherEngine::readFromInotify() } } -QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const +template <typename Hash, typename Key> +typename Hash::const_iterator +find_last_in_equal_range(const Hash &c, const Key &key) { - QHash<int, QString>::const_iterator i = idToPath.find(id); - while (i != idToPath.constEnd() && i.key() == id) { - if ((i + 1) == idToPath.constEnd() || (i + 1).key() != id) { - return i.value(); - } + // find c.equal_range(key).second - 1 without backwards iteration: + auto i = c.find(key); + const auto end = c.cend(); + if (i == end) + return end; + decltype(i) prev; + do { + prev = i; ++i; - } - return QString(); + } while (i != end && i.key() == key); + return prev; +} + +QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const +{ + auto i = find_last_in_equal_range(idToPath, id); + return i == idToPath.cend() ? QString() : i.value() ; } QT_END_NAMESPACE |