X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/99e80c1c7e6e77aa26ccbca4fbb0430b35974544..405dd624fb:/src/views/draganddrophelper.cpp diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index 831a9d43e..d248d00eb 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -20,21 +20,29 @@ #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) @@ -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(); }