┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/private/kdirectorycontentscounterworker.cpp
diff options
context:
space:
mode:
authorMéven Car <[email protected]>2023-02-12 11:21:53 +0000
committerMéven Car <[email protected]>2023-02-12 11:21:53 +0000
commitba930ddb3635fe2d94d727e72aaf261513b28060 (patch)
tree9199f7944d1b02830eb05f15a58fe1b1be1edbce /src/kitemviews/private/kdirectorycontentscounterworker.cpp
parenta15def4e64dc08d508e7a511a20ad06e7e8a2e0c (diff)
Optimize Directory size counting
Two changes: * Prioritise size counting for visible path * stop the worker when switching dirs
Diffstat (limited to 'src/kitemviews/private/kdirectorycontentscounterworker.cpp')
-rw-r--r--src/kitemviews/private/kdirectorycontentscounterworker.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/kitemviews/private/kdirectorycontentscounterworker.cpp b/src/kitemviews/private/kdirectorycontentscounterworker.cpp
index e227c1bc6..2227ebbc2 100644
--- a/src/kitemviews/private/kdirectorycontentscounterworker.cpp
+++ b/src/kitemviews/private/kdirectorycontentscounterworker.cpp
@@ -25,7 +25,7 @@ KDirectoryContentsCounterWorker::KDirectoryContentsCounterWorker(QObject *parent
#ifndef Q_OS_WIN
KDirectoryContentsCounterWorker::CountResult
-walkDir(const QString &dirPath, const bool countHiddenFiles, const bool countDirectoriesOnly, const uint allowedRecursiveLevel)
+KDirectoryContentsCounterWorker::walkDir(const QString &dirPath, const bool countHiddenFiles, const bool countDirectoriesOnly, const uint allowedRecursiveLevel)
{
int count = -1;
long size = -1;
@@ -36,7 +36,7 @@ walkDir(const QString &dirPath, const bool countHiddenFiles, const bool countDir
QT_DIRENT *dirEntry;
QT_STATBUF buf;
- while ((dirEntry = QT_READDIR(dir))) {
+ while (!m_stopping && (dirEntry = QT_READDIR(dir))) {
if (dirEntry->d_name[0] == '.') {
if (dirEntry->d_name[1] == '\0' || !countHiddenFiles) {
// Skip "." or hidden files
@@ -64,7 +64,7 @@ walkDir(const QString &dirPath, const bool countHiddenFiles, const bool countDir
size += buf.st_size;
}
}
- if (dirEntry->d_type == DT_DIR) {
+ if (!m_stopping && dirEntry->d_type == DT_DIR) {
// recursion for dirs
auto subdirResult = walkDir(nameBuf, countHiddenFiles, countDirectoriesOnly, allowedRecursiveLevel - 1);
if (subdirResult.size > 0) {
@@ -106,8 +106,18 @@ KDirectoryContentsCounterWorker::CountResult KDirectoryContentsCounterWorker::su
#endif
}
+void KDirectoryContentsCounterWorker::stop()
+{
+ m_stopping = true;
+}
+
void KDirectoryContentsCounterWorker::countDirectoryContents(const QString &path, Options options)
{
+ m_stopping = false;
+
auto res = subItemsCount(path, options);
- Q_EMIT result(path, res.count, res.size);
+
+ if (!m_stopping) {
+ Q_EMIT result(path, res.count, res.size);
+ }
}