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,22 @@ #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(); + auto iteratorResult = m_cacheUrlListMatchesUrl.find(destUrl); + // if m_cacheUrlListMatchesUrl does not contains destUrl + if (iteratorResult == m_cacheUrlListMatchesUrl.end()) { + // return the value inserted, that is calculated + return *m_cacheUrlListMatchesUrl.insert(destUrl, + // Iterating the list until a node matches destUrl + std::find_if(urls.constBegin(), urls.constEnd(), [destUrl](const QUrl& url) { + return url.matches(destUrl, QUrl::StripTrailingSlash); + // and comparing it with the imaginary end of the list + }) != urls.constEnd() ); + } + return *iteratorResult; } KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event, QWidget* window) @@ -53,7 +63,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 +72,8 @@ return nullptr; } +void DragAndDropHelper::clearCacheUrlListMatchesUrl() +{ + DragAndDropHelper::m_cacheUrlListMatchesUrl.clear(); +} +