]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/draganddrophelper.cpp
Faster drag&drop in directories with thousands of files
[dolphin.git] / src / views / draganddrophelper.cpp
index e944227df9f9859d01382041202b821145c842b0..4d76992cadcda90f49f8f97bed5a6e0e34ac5cff 100644 (file)
 #include <KIO/DropJob>
 #include <KJobWidgets>
 
+QHash<QUrl, bool> DragAndDropHelper::m_urlListMatchesUrlCache;
 
 bool DragAndDropHelper::urlListMatchesUrl(const QList<QUrl>& urls, const QUrl& destUrl)
 {
-    return std::find_if(urls.constBegin(), urls.constEnd(), [destUrl](const QUrl& url) {
-        return url.matches(destUrl, QUrl::StripTrailingSlash);
-    }) != urls.constEnd();
+    auto iteratorResult = m_urlListMatchesUrlCache.constFind(destUrl);
+    if (iteratorResult != m_urlListMatchesUrlCache.constEnd()) {
+        return *iteratorResult;
+    }
+
+    const bool destUrlMatches =
+        std::find_if(urls.constBegin(), urls.constEnd(), [destUrl](const QUrl& url) {
+            return url.matches(destUrl, QUrl::StripTrailingSlash);
+        }) != urls.constEnd();
+
+    return *m_urlListMatchesUrlCache.insert(destUrl, destUrlMatches);
 }
 
 KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event, QWidget* window)
@@ -63,3 +72,8 @@ KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event
     return nullptr;
 }
 
+void DragAndDropHelper::clearUrlListMatchesUrlCache()
+{
+    DragAndDropHelper::m_urlListMatchesUrlCache.clear();
+}
+