diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -849,6 +849,9 @@ { Q_UNUSED(event); Q_UNUSED(transform); + + DragAndDropHelper::clearCacheUrlListMatchesUrl(); + return false; } @@ -875,7 +878,6 @@ return false; } - QUrl hoveredDir = m_model->directory(); KItemListWidget* oldHoveredWidget = hoveredWidget(); diff --git a/src/views/draganddrophelper.h b/src/views/draganddrophelper.h --- a/src/views/draganddrophelper.h +++ b/src/views/draganddrophelper.h @@ -54,6 +54,16 @@ * @return True if destUrl is contained in the urls parameter. */ static bool urlListMatchesUrl(const QList& urls, const QUrl& destUrl); + + /** + * clear the internal cache. + */ + static void clearCacheUrlListMatchesUrl(); +private: + /** + * Stores the results of the expensive checks made in urlListMatchesUrl. + */ + static QHash m_cacheUrlListMatchesUrl; }; #endif diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -29,12 +29,18 @@ #include #include +QHash DragAndDropHelper::m_cacheUrlListMatchesUrl; bool DragAndDropHelper::urlListMatchesUrl(const QList& urls, const QUrl& destUrl) { - return std::find_if(urls.constBegin(), urls.constEnd(), [destUrl](const QUrl& url) { - return url.matches(destUrl, QUrl::StripTrailingSlash); - }) != urls.constEnd(); + if (!m_cacheUrlListMatchesUrl.contains(destUrl)) + { + m_cacheUrlListMatchesUrl.insert(destUrl, + std::find_if(urls.constBegin(), urls.constEnd(), [destUrl](const QUrl& url) { + return url.matches(destUrl, QUrl::StripTrailingSlash); + }) != urls.constEnd() ); + } + return m_cacheUrlListMatchesUrl[destUrl]; } KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event, QWidget* window) @@ -53,7 +59,6 @@ if (urlListMatchesUrl(event->mimeData()->urls(), destUrl)) { return nullptr; } - // Drop into a directory or a desktop-file KIO::DropJob *job = KIO::drop(event, destUrl); KJobWidgets::setWindow(job, window); @@ -63,3 +68,8 @@ return nullptr; } +void DragAndDropHelper::clearCacheUrlListMatchesUrl() +{ + DragAndDropHelper::m_cacheUrlListMatchesUrl.clear(); +} +