From 32629676b977d98e853fc6101a63c0d888ff5598 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 22 Apr 2013 08:34:53 +0200 Subject: Use a QVector instead of an array in QFileInfoPrivate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since QDateTime is pimpled, default allocation is expensive and regularly shows up in profiles of code using QFileInfo. For Qt 6, QDateTime's data members should be put into the class proper, and this change here reverted. Change-Id: I94a50e467b12772e1076181eb2ac6031984d8802 Reviewed-by: Thorbjørn Lindeijer Reviewed-by: Stephen Kelly --- src/corelib/io/qfileinfo.cpp | 2 ++ src/corelib/io/qfileinfo_p.h | 8 +++++++- src/corelib/tools/qdatetime.h | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 7fcb4154f2..addcd772ab 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -187,6 +187,8 @@ 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; diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h index 1b254f6e85..442e6b5ef0 100644 --- a/src/corelib/io/qfileinfo_p.h +++ b/src/corelib/io/qfileinfo_p.h @@ -58,6 +58,7 @@ #include "qatomic.h" #include "qshareddata.h" #include "qfilesystemengine_p.h" +#include "qvector.h" #include #include @@ -152,7 +153,12 @@ public: bool cache_enabled : 1; mutable uint fileFlags; mutable qint64 fileSize; - mutable QDateTime fileTimes[3]; + // ### 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 diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index d1cc10c877..5c1668033c 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -262,6 +262,10 @@ public: private: friend class QDateTimePrivate; void detach(); + + // ### Qt6: Using a private here has high impact on runtime + // on users such as QFileInfo. In Qt 6, the data members + // should be inlined. QExplicitlySharedDataPointer d; #ifndef QT_NO_DATASTREAM -- cgit v1.2.3