Decompress QResources only when needed.
In particular, just creating a QFileInfo (or a QDirIterator, which uses QFileInfo internally) no longer triggers decompression. This doubles the performance when using a QDirIterator/QFile combo for loading a bunch of files. Change-Id: I7f53354e890ad6360693b7848d21a0cd5d595628 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
249cb94655
commit
5e059c6047
@ -1194,9 +1194,10 @@ protected:
|
|||||||
private:
|
private:
|
||||||
uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
|
uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
|
||||||
bool unmap(uchar *ptr);
|
bool unmap(uchar *ptr);
|
||||||
|
void uncompress() const;
|
||||||
qint64 offset;
|
qint64 offset;
|
||||||
QResource resource;
|
QResource resource;
|
||||||
QByteArray uncompressed;
|
mutable QByteArray uncompressed;
|
||||||
protected:
|
protected:
|
||||||
QResourceFileEnginePrivate() : offset(0) { }
|
QResourceFileEnginePrivate() : offset(0) { }
|
||||||
};
|
};
|
||||||
@ -1231,13 +1232,6 @@ QResourceFileEngine::QResourceFileEngine(const QString &file) :
|
|||||||
{
|
{
|
||||||
Q_D(QResourceFileEngine);
|
Q_D(QResourceFileEngine);
|
||||||
d->resource.setFileName(file);
|
d->resource.setFileName(file);
|
||||||
if(d->resource.isCompressed() && d->resource.size()) {
|
|
||||||
#ifndef QT_NO_COMPRESS
|
|
||||||
d->uncompressed = qUncompress(d->resource.data(), d->resource.size());
|
|
||||||
#else
|
|
||||||
Q_ASSERT(!"QResourceFileEngine::open: Qt built without support for compression");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QResourceFileEngine::~QResourceFileEngine()
|
QResourceFileEngine::~QResourceFileEngine()
|
||||||
@ -1259,6 +1253,7 @@ bool QResourceFileEngine::open(QIODevice::OpenMode flags)
|
|||||||
}
|
}
|
||||||
if(flags & QIODevice::WriteOnly)
|
if(flags & QIODevice::WriteOnly)
|
||||||
return false;
|
return false;
|
||||||
|
d->uncompress();
|
||||||
if (!d->resource.isValid()) {
|
if (!d->resource.isValid()) {
|
||||||
d->errorString = qt_error_string(ENOENT);
|
d->errorString = qt_error_string(ENOENT);
|
||||||
return false;
|
return false;
|
||||||
@ -1324,8 +1319,10 @@ qint64 QResourceFileEngine::size() const
|
|||||||
Q_D(const QResourceFileEngine);
|
Q_D(const QResourceFileEngine);
|
||||||
if(!d->resource.isValid())
|
if(!d->resource.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
if(d->resource.isCompressed())
|
if (d->resource.isCompressed()) {
|
||||||
|
d->uncompress();
|
||||||
return d->uncompressed.size();
|
return d->uncompressed.size();
|
||||||
|
}
|
||||||
return d->resource.size();
|
return d->resource.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1493,6 +1490,18 @@ bool QResourceFileEnginePrivate::unmap(uchar *ptr)
|
|||||||
Q_UNUSED(ptr);
|
Q_UNUSED(ptr);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QResourceFileEnginePrivate::uncompress() const
|
||||||
|
{
|
||||||
|
if (resource.isCompressed() && uncompressed.isEmpty() && resource.size()) {
|
||||||
|
#ifndef QT_NO_COMPRESS
|
||||||
|
uncompressed = qUncompress(resource.data(), resource.size());
|
||||||
|
#else
|
||||||
|
Q_ASSERT(!"QResourceFileEngine::open: Qt built without support for compression");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(QT_BOOTSTRAPPED)
|
#endif // !defined(QT_BOOTSTRAPPED)
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user