diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-12-14 18:26:33 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2024-02-09 18:44:23 +0200 |
commit | 83f7125ac866ed5a2aaace56ffc866f21f9730b4 (patch) | |
tree | 516df9233f82076d678c11733b0d2520813f18a9 /src/corelib/io/qfilesystemiterator_p.h | |
parent | 74722411d3fbfcc30d8eff98efcc627be451aea9 (diff) |
QFileSystemIterator/Unix: use QStringDecoder
The end result is a QFileInfo constructed from the QFileSystemEntry;
QFileSystemEntry's API will at some point convert the NativePath (QBA on
Unix) to a QString, e.g. when it calls findLastSeparator().
So instead of converting the parent dir path from Utf8 to Utf16 multiple
times, store the dir path as a QString once in the constructor.
Use QStringDecoder to convert the dirent->d_name to Utf16 and check the
decoder's hasError(); which as Thiago pointed out, is more efficient
than using isValidUtf8(), throwing away the results, then converting to
unicode anyway later on in QDirIteratorPrivate::advance().
(Ironically) `QFileSystemEntry::NativePath nativePath` is still used on
Windows.
Change-Id: Icd2b130103640b502862d210d64926b99c499a01
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfilesystemiterator_p.h')
-rw-r--r-- | src/corelib/io/qfilesystemiterator_p.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/corelib/io/qfilesystemiterator_p.h b/src/corelib/io/qfilesystemiterator_p.h index 6638016a41..5687da115e 100644 --- a/src/corelib/io/qfilesystemiterator_p.h +++ b/src/corelib/io/qfilesystemiterator_p.h @@ -26,6 +26,10 @@ #include <QtCore/private/qfilesystementry_p.h> #include <QtCore/private/qfilesystemmetadata_p.h> +#if !defined(Q_OS_WIN) +#include <private/qstringconverter_p.h> +#endif + #include <memory> QT_BEGIN_NAMESPACE @@ -39,11 +43,11 @@ public: bool advance(QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData); private: - QFileSystemEntry::NativePath nativePath; + QString dirPath; // Platform-specific data #if defined(Q_OS_WIN) - QString dirPath; + QFileSystemEntry::NativePath nativePath; HANDLE findFileHandle; QStringList uncShares; bool uncFallback; @@ -58,6 +62,7 @@ private: QT_DIRENT *dirEntry = nullptr; int lastError = 0; + QStringDecoder toUtf16; #endif Q_DISABLE_COPY_MOVE(QFileSystemIterator) |