]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/draganddrophelper.cpp
Merge branch 'Applications/19.08'
[dolphin.git] / src / views / draganddrophelper.cpp
index e944227df9f9859d01382041202b821145c842b0..d437b877ead7ec02249479affb134a83fed8d76b 100644 (file)
 
 #include "draganddrophelper.h"
 
-#include <QUrl>
-#include <QDBusMessage>
-#include <QDBusConnection>
-#include <QDropEvent>
-#include <QMimeData>
-
 #include <KIO/DropJob>
 #include <KJobWidgets>
 
+#include <QDBusConnection>
+#include <QDBusMessage>
+#include <QMimeData>
+
+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 +70,8 @@ KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event
     return nullptr;
 }
 
+void DragAndDropHelper::clearUrlListMatchesUrlCache()
+{
+    DragAndDropHelper::m_urlListMatchesUrlCache.clear();
+}
+