Improve performance of QResource::load()
Avoid creating a QDateTime in the resource that will almost never get used. Constructing the date time is expensive as we convert the time stamp to local time. Task-number: QTBUG-65713 Change-Id: I3638e108a8fbd237cd93e98aa2adc0ca2127822c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Tuukka Turunen <tuukka.turunen@qt.io>
This commit is contained in:
parent
a8906e3510
commit
07f1c96658
@ -116,7 +116,7 @@ public:
|
||||
inline bool isContainer(int node) const { return flags(node) & Directory; }
|
||||
inline bool isCompressed(int node) const { return flags(node) & Compressed; }
|
||||
const uchar *data(int node, qint64 *size) const;
|
||||
QDateTime lastModified(int node) const;
|
||||
quint64 lastModified(int node) const;
|
||||
QStringList children(int node) const;
|
||||
virtual QString mappingRoot() const { return QString(); }
|
||||
bool mappingRootSubdir(const QString &path, QString *match=0) const;
|
||||
@ -245,7 +245,7 @@ public:
|
||||
mutable qint64 size;
|
||||
mutable const uchar *data;
|
||||
mutable QStringList children;
|
||||
mutable QDateTime lastModified;
|
||||
mutable quint64 lastModified;
|
||||
|
||||
QResource *q_ptr;
|
||||
Q_DECLARE_PUBLIC(QResource)
|
||||
@ -259,7 +259,7 @@ QResourcePrivate::clear()
|
||||
data = 0;
|
||||
size = 0;
|
||||
children.clear();
|
||||
lastModified = QDateTime();
|
||||
lastModified = 0;
|
||||
container = 0;
|
||||
for(int i = 0; i < related.size(); ++i) {
|
||||
QResourceRoot *root = related.at(i);
|
||||
@ -301,7 +301,7 @@ QResourcePrivate::load(const QString &file)
|
||||
data = 0;
|
||||
size = 0;
|
||||
compressed = 0;
|
||||
lastModified = QDateTime();
|
||||
lastModified = 0;
|
||||
res->ref.ref();
|
||||
related.append(res);
|
||||
}
|
||||
@ -539,7 +539,7 @@ QDateTime QResource::lastModified() const
|
||||
{
|
||||
Q_D(const QResource);
|
||||
d->ensureInitialized();
|
||||
return d->lastModified;
|
||||
return d->lastModified ? QDateTime::fromMSecsSinceEpoch(d->lastModified) : QDateTime();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -797,18 +797,14 @@ const uchar *QResourceRoot::data(int node, qint64 *size) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
QDateTime QResourceRoot::lastModified(int node) const
|
||||
quint64 QResourceRoot::lastModified(int node) const
|
||||
{
|
||||
if (node == -1 || version < 0x02)
|
||||
return QDateTime();
|
||||
return 0;
|
||||
|
||||
const int offset = findOffset(node) + 14;
|
||||
|
||||
const quint64 timeStamp = qFromBigEndian<quint64>(tree + offset);
|
||||
if (timeStamp == 0)
|
||||
return QDateTime();
|
||||
|
||||
return QDateTime::fromMSecsSinceEpoch(timeStamp);
|
||||
return qFromBigEndian<quint64>(tree + offset);
|
||||
}
|
||||
|
||||
QStringList QResourceRoot::children(int node) const
|
||||
|
Loading…
Reference in New Issue
Block a user