X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/1a6b3c0a2baba955259d6083c0a3f25dfb44a682..87f30d3fc8172649b3c905b04e20655ca18ac68f:/src/views/draganddrophelper.cpp diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index e944227df..d437b877e 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -20,21 +20,28 @@ #include "draganddrophelper.h" -#include -#include -#include -#include -#include - #include #include +#include +#include +#include + +QHash DragAndDropHelper::m_urlListMatchesUrlCache; 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_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(); +} +