diff options
| author | Jaime Torres <[email protected]> | 2018-02-04 21:19:33 +0100 |
|---|---|---|
| committer | Jaime Torres <[email protected]> | 2018-02-05 19:25:44 +0100 |
| commit | 9fbf7a0b624aee6b116efdf69462e73f0275fab6 (patch) | |
| tree | 23d2da280aeda134048aec882cf8201d27fca209 /src/views/draganddrophelper.cpp | |
| parent | 20d57ab48875a4a8cff440254dc379e4bc1393bc (diff) | |
Faster drag&drop in directories with thousands of files
Summary:
The check is called when the mouse is moved in a drag&drop operation.
Dragging all files in a directory with 3000 files under callgrind,
moving the mouse to the other panel and then canceling, doing it twice,
callgrind shows that the method urlListMatchesUrl is called around
200 times, spending around 9,30% of the cpu in those calls.
Applying the patch, callgrind tells it uses now 0.31% of the cpu in 1208 calls.
CCBUG: 342056
Reviewers: #dolphin, elvisangelaccio, markg
Reviewed By: #dolphin, elvisangelaccio, markg
Subscribers: markg, anthonyfieroni, michaelh, elvisangelaccio, ngraham
Differential Revision: https://phabricator.kde.org/D10085
Diffstat (limited to 'src/views/draganddrophelper.cpp')
| -rw-r--r-- | src/views/draganddrophelper.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index e944227df..4d76992ca 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -29,12 +29,21 @@ #include <KIO/DropJob> #include <KJobWidgets> +QHash<QUrl, bool> DragAndDropHelper::m_urlListMatchesUrlCache; bool DragAndDropHelper::urlListMatchesUrl(const QList<QUrl>& 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 +72,8 @@ KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event return nullptr; } +void DragAndDropHelper::clearUrlListMatchesUrlCache() +{ + DragAndDropHelper::m_urlListMatchesUrlCache.clear(); +} + |
