]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/draganddrophelper.cpp
SVN_SILENT made messages (.desktop file) - always resolve ours
[dolphin.git] / src / views / draganddrophelper.cpp
index 831a9d43e08be707514235df07fb87435b80cf4c..d248d00ebc950a1652f66a2559460bf606ca277a 100644 (file)
 
 #include "draganddrophelper.h"
 
-#include <QUrl>
-#include <QDBusMessage>
+#include <KIO/DropJob>
+#include <KJobWidgets>
+
 #include <QDBusConnection>
+#include <QDBusMessage>
 #include <QDropEvent>
 #include <QMimeData>
 
-#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)
@@ -60,6 +68,11 @@ KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event
         return job;
     }
 
-    return 0;
+    return nullptr;
+}
+
+void DragAndDropHelper::clearUrlListMatchesUrlCache()
+{
+    DragAndDropHelper::m_urlListMatchesUrlCache.clear();
 }