Stop using QVector in QFileInfoPrivate
This was added in 32629676b9 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>
bb10
parent
0b7d9d2811
commit
49ab284d34
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue