From 49ab284d3445c61a0ea819bbe2dd2ed54241d2e9 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 25 Oct 2016 15:52:55 -0700 Subject: [PATCH] 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 --- src/corelib/io/qfileinfo.cpp | 21 +++++++++++++-------- src/corelib/io/qfileinfo_p.h | 10 ++-------- 2 files changed, 15 insertions(+), 16 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) - cf = CachedCTime; - else if (request == QAbstractFileEngine::ModificationTime) - cf = CachedMTime; - else + + uint cf = 0; + switch (request) { + case QAbstractFileEngine::AccessTime: cf = CachedATime; + break; + case QAbstractFileEngine::CreationTime: + cf = CachedCTime; + break; + case QAbstractFileEngine::ModificationTime: + cf = CachedMTime; + 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 #include @@ -158,19 +157,14 @@ public: QScopedPointer 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 fileTimes; inline bool getCachedFlag(uint c) const { return cache_enabled ? (cachedFlags & c) : 0; } inline void setCachedFlag(uint c) const