diff options
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.cpp | 3 | ||||
| -rw-r--r-- | src/views/draganddrophelper.cpp | 20 | ||||
| -rw-r--r-- | src/views/draganddrophelper.h | 10 |
3 files changed, 30 insertions, 3 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 130936488..7af8781b4 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -849,6 +849,9 @@ bool KItemListController::dragEnterEvent(QGraphicsSceneDragDropEvent* event, con { Q_UNUSED(event); Q_UNUSED(transform); + + DragAndDropHelper::clearUrlListMatchesUrlCache(); + return false; } diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index e944227df..4d76992ca 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -29,12 +29,21 @@ #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(); +} + diff --git a/src/views/draganddrophelper.h b/src/views/draganddrophelper.h index e47f83ca8..0c7eadc6c 100644 --- a/src/views/draganddrophelper.h +++ b/src/views/draganddrophelper.h @@ -54,6 +54,16 @@ public: * @return True if destUrl is contained in the urls parameter. */ static bool urlListMatchesUrl(const QList<QUrl>& urls, const QUrl& destUrl); + + /** + * clear the internal cache. + */ + static void clearUrlListMatchesUrlCache(); +private: + /** + * Stores the results of the expensive checks made in urlListMatchesUrl. + */ + static QHash<QUrl, bool> m_urlListMatchesUrlCache; }; #endif |
