QZip*: don't hold QZipReader::FileInfo in QList
FileInfo is larger than a void*, so holding them in a QList is needlessly inefficient. Worse, the code could come to depend on the fragile property of (inefficient) QLists that references to elements therein never are invalidated. Change-Id: I772177c5ac544a5fecce2368f628148308ef260f Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
78bba7b002
commit
0abd207052
@ -430,7 +430,7 @@ public:
|
||||
QIODevice *device;
|
||||
bool ownDevice;
|
||||
bool dirtyFileTree;
|
||||
QList<FileHeader> fileHeaders;
|
||||
QVector<FileHeader> fileHeaders;
|
||||
QByteArray comment;
|
||||
uint start_of_directory;
|
||||
};
|
||||
@ -889,10 +889,10 @@ bool QZipReader::exists() const
|
||||
/*!
|
||||
Returns the list of files the archive contains.
|
||||
*/
|
||||
QList<QZipReader::FileInfo> QZipReader::fileInfoList() const
|
||||
QVector<QZipReader::FileInfo> QZipReader::fileInfoList() const
|
||||
{
|
||||
d->scanFiles();
|
||||
QList<QZipReader::FileInfo> files;
|
||||
QVector<FileInfo> files;
|
||||
const int numFileHeaders = d->fileHeaders.size();
|
||||
files.reserve(numFileHeaders);
|
||||
for (int i = 0; i < numFileHeaders; ++i) {
|
||||
@ -1022,7 +1022,7 @@ bool QZipReader::extractAll(const QString &destinationDir) const
|
||||
QDir baseDir(destinationDir);
|
||||
|
||||
// create directories first
|
||||
QList<FileInfo> allFiles = fileInfoList();
|
||||
const QVector<FileInfo> allFiles = fileInfoList();
|
||||
foreach (const FileInfo &fi, allFiles) {
|
||||
const QString absPath = destinationDir + QDir::separator() + fi.filePath;
|
||||
if (fi.isDir) {
|
||||
|
@ -88,7 +88,7 @@ public:
|
||||
QDateTime lastModified;
|
||||
};
|
||||
|
||||
QList<FileInfo> fileInfoList() const;
|
||||
QVector<FileInfo> fileInfoList() const;
|
||||
int count() const;
|
||||
|
||||
FileInfo entryInfoAt(int index) const;
|
||||
|
@ -50,7 +50,7 @@ private slots:
|
||||
void tst_QZip::basicUnpack()
|
||||
{
|
||||
QZipReader zip(QFINDTESTDATA("/testdata/test.zip"), QIODevice::ReadOnly);
|
||||
QList<QZipReader::FileInfo> files = zip.fileInfoList();
|
||||
QVector<QZipReader::FileInfo> files = zip.fileInfoList();
|
||||
QCOMPARE(files.count(), 2);
|
||||
|
||||
QZipReader::FileInfo fi = files.at(0);
|
||||
@ -86,7 +86,7 @@ void tst_QZip::basicUnpack()
|
||||
void tst_QZip::symlinks()
|
||||
{
|
||||
QZipReader zip(QFINDTESTDATA("/testdata/symlink.zip"), QIODevice::ReadOnly);
|
||||
QList<QZipReader::FileInfo> files = zip.fileInfoList();
|
||||
QVector<QZipReader::FileInfo> files = zip.fileInfoList();
|
||||
QCOMPARE(files.count(), 2);
|
||||
|
||||
QZipReader::FileInfo fi = files.at(0);
|
||||
@ -109,7 +109,7 @@ void tst_QZip::symlinks()
|
||||
void tst_QZip::readTest()
|
||||
{
|
||||
QZipReader zip("foobar.zip", QIODevice::ReadOnly); // non existing file.
|
||||
QList<QZipReader::FileInfo> files = zip.fileInfoList();
|
||||
QVector<QZipReader::FileInfo> files = zip.fileInfoList();
|
||||
QCOMPARE(files.count(), 0);
|
||||
QByteArray b = zip.fileData("foobar");
|
||||
QCOMPARE(b.size(), 0);
|
||||
@ -128,7 +128,7 @@ void tst_QZip::createArchive()
|
||||
|
||||
QBuffer buffer2(&zipFile);
|
||||
QZipReader zip2(&buffer2);
|
||||
QList<QZipReader::FileInfo> files = zip2.fileInfoList();
|
||||
QVector<QZipReader::FileInfo> files = zip2.fileInfoList();
|
||||
QCOMPARE(files.count(), 1);
|
||||
QZipReader::FileInfo file = files.at(0);
|
||||
QCOMPARE(file.filePath, QString("My Filename"));
|
||||
|
Loading…
Reference in New Issue
Block a user