diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2016-10-25 15:52:55 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-07-07 18:40:31 +0000 |
commit | 49ab284d3445c61a0ea819bbe2dd2ed54241d2e9 (patch) | |
tree | b874dd840d17e1c6bbb7d95c309df84495cca40f | |
parent | 0b7d9d28119d27bd6ccb277876f4d904d1d7afcb (diff) |
Stop using QVector in QFileInfoPrivate
This was added in 32629676b977d98e853fc6101a63c0d888ff5598 for Qt 5.1
because QDateTime always allocated memory, so QVector was much faster
for default-created objects. Since Qt 5.7, QDateTime no longer allocates
memory in the default constructor, and in Qt 5.8 on 64-bit systems, it
won't allocate memory at all for most reasonable dates, so construction
times are acceptable now.
Change-Id: If0ad4d988da143b3b1b2fffd1480e83121cddc8c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 19 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo_p.h | 10 |
2 files changed, 14 insertions, 15 deletions
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index f7358d61b3..d301b10004 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -186,17 +186,22 @@ uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) cons QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) const { Q_ASSERT(fileEngine); // should never be called when using the native FS - if (fileTimes.size() != 3) - fileTimes.resize(3); if (!cache_enabled) clearFlags(); - uint cf; - if (request == QAbstractFileEngine::CreationTime) + + uint cf = 0; + switch (request) { + case QAbstractFileEngine::AccessTime: + cf = CachedATime; + break; + case QAbstractFileEngine::CreationTime: cf = CachedCTime; - else if (request == QAbstractFileEngine::ModificationTime) + break; + case QAbstractFileEngine::ModificationTime: cf = CachedMTime; - else - cf = CachedATime; + break; + } + if (!getCachedFlag(cf)) { fileTimes[request] = fileEngine->fileTime(request); setCachedFlag(cf); diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h index 806df179e8..d45cf6be33 100644 --- a/src/corelib/io/qfileinfo_p.h +++ b/src/corelib/io/qfileinfo_p.h @@ -56,7 +56,6 @@ #include "qatomic.h" #include "qshareddata.h" #include "qfilesystemengine_p.h" -#include "qvector.h" #include <QtCore/private/qabstractfileengine_p.h> #include <QtCore/private/qfilesystementry_p.h> @@ -158,19 +157,14 @@ public: QScopedPointer<QAbstractFileEngine> const fileEngine; mutable QString fileNames[QAbstractFileEngine::NFileNames]; - mutable QString fileOwners[2]; + mutable QString fileOwners[2]; // QAbstractFileEngine::FileOwner: OwnerUser and OwnerGroup + mutable QDateTime fileTimes[4]; // QAbstractFileEngine::FileTime: BirthTime, MetadataChangeTime, ModificationTime, AccessTime mutable uint cachedFlags : 30; bool const isDefaultConstructed : 1; // QFileInfo is a default constructed instance bool cache_enabled : 1; mutable uint fileFlags; mutable qint64 fileSize; - // ### Qt6: FIXME: This vector is essentially a plain array - // mutable QDateTime fileTimes[3], but the array is slower - // to initialize than the QVector as QDateTime has a pimpl. - // In Qt 6, QDateTime should inline its data members, - // and this here can be an array again. - mutable QVector<QDateTime> fileTimes; inline bool getCachedFlag(uint c) const { return cache_enabled ? (cachedFlags & c) : 0; } inline void setCachedFlag(uint c) const |