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,25 @@ #include #include - bool DragAndDropHelper::urlListMatchesUrl(const QList& urls, const QUrl& destUrl) { - return std::find_if(urls.constBegin(), urls.constEnd(), [destUrl](const QUrl& url) { + // This method is quite expensive and can be called several times. Use a cache. + static bool lastResult = false; + static const QList* lastUrls = nullptr; + static const QUrl* lastDestUrl = nullptr; + + // If checking the same data as last time, return the same resutl. + if (&urls == lastUrls && &destUrl == lastDestUrl) { + return lastResult; + } + // otherwise do the expensive check and store the results + lastResult = std::find_if(urls.constBegin(), urls.constEnd(), [destUrl](const QUrl& url) { return url.matches(destUrl, QUrl::StripTrailingSlash); }) != urls.constEnd(); + lastUrls = &urls; + lastDestUrl = &destUrl; + + return lastResult; } KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event, QWidget* window)