Changeset View
Changeset View
Standalone View
Standalone View
src/filemetadataprovider.cpp
Show First 20 Lines • Show All 490 Lines • ▼ Show 20 Line(s) | |||||
491 | #ifdef Q_OS_WIN | 491 | #ifdef Q_OS_WIN | ||
492 | QDir dir(path); | 492 | QDir dir(path); | ||
493 | return dir.entryList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::System).count(); | 493 | return dir.entryList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::System).count(); | ||
494 | #else | 494 | #else | ||
495 | // Taken from kdelibs/kio/kio/kdirmodel.cpp | 495 | // Taken from kdelibs/kio/kio/kdirmodel.cpp | ||
496 | // Copyright (C) 2006 David Faure <faure@kde.org> | 496 | // Copyright (C) 2006 David Faure <faure@kde.org> | ||
497 | 497 | | |||
498 | int count = -1; | 498 | int count = -1; | ||
499 | DIR* dir = ::opendir(QFile::encodeName(path)); | 499 | DIR* dir = ::opendir(QFile::encodeName(path).constData()); | ||
500 | if (dir) { | 500 | if (dir) { | ||
501 | count = 0; | 501 | count = 0; | ||
502 | struct dirent *dirEntry = nullptr; | 502 | struct dirent *dirEntry = nullptr; | ||
503 | while ((dirEntry = ::readdir(dir))) { // krazy:exclude=syscalls | 503 | while ((dirEntry = ::readdir(dir))) { // krazy:exclude=syscalls | ||
504 | if (dirEntry->d_name[0] == '.') { | 504 | if (dirEntry->d_name[0] == '.') { | ||
505 | if (dirEntry->d_name[1] == '\0') { | 505 | if (dirEntry->d_name[1] == '\0') { | ||
506 | // Skip "." | 506 | // Skip "." | ||
507 | continue; | 507 | continue; | ||
508 | } | 508 | } | ||
509 | if (dirEntry->d_name[1] == '.' && dirEntry->d_name[2] == '\0') { | 509 | if (dirEntry->d_name[1] == '.' && dirEntry->d_name[2] == '\0') { | ||
510 | // Skip ".." | 510 | // Skip ".." | ||
511 | continue; | 511 | continue; | ||
512 | } | 512 | } | ||
513 | } | 513 | } | ||
514 | ++count; | 514 | ++count; | ||
515 | } | 515 | } | ||
516 | ::closedir(dir); | 516 | ::closedir(dir); | ||
517 | } | 517 | } | ||
518 | return count; | 518 | return count; | ||
519 | #endif | 519 | #endif | ||
astippich: disclaimer: I don't know why it was added like this before, but using the way it is done in… | |||||
very likely for performance/memory reasons. This should at least use a QDirIterator, otherwise entryList(...) will allocate a lot of memory for large directories. Please create a directory with 10000 entries and benchmark all variants. bruns: very likely for performance/memory reasons.
This should at least use a `QDirIterator`… | |||||
You were right. astippich: You were right.
Benchmark showed that QDir is about 10x slower, file QDirIterator still around… | |||||
520 | } | 520 | } | ||
521 | 521 | | |||
522 | bool FileMetaDataProvider::realTimeIndexing() | 522 | bool FileMetaDataProvider::realTimeIndexing() | ||
523 | { | 523 | { | ||
524 | return m_realTimeIndexing; | 524 | return m_realTimeIndexing; | ||
525 | } | 525 | } |
disclaimer: I don't know why it was added like this before, but using the way it is done in windows seems to work just fine.