QZip*: return FileInfo by value

Makes for much more readable callers, and, d/t NRVO, isn't less efficient
than the old code, either. Transparently enables moves when QVector should
get them, at some point, too.

Change-Id: I77327cf665272b80277deaaa6dd2ee9c00806464
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-06-24 10:14:30 +02:00
parent 0abd207052
commit aa2efdfa97

View File

@ -425,7 +425,7 @@ public:
delete device; delete device;
} }
void fillFileInfo(int index, QZipReader::FileInfo &fileInfo) const; QZipReader::FileInfo fillFileInfo(int index) const;
QIODevice *device; QIODevice *device;
bool ownDevice; bool ownDevice;
@ -435,8 +435,9 @@ public:
uint start_of_directory; uint start_of_directory;
}; };
void QZipPrivate::fillFileInfo(int index, QZipReader::FileInfo &fileInfo) const QZipReader::FileInfo QZipPrivate::fillFileInfo(int index) const
{ {
QZipReader::FileInfo fileInfo;
FileHeader header = fileHeaders.at(index); FileHeader header = fileHeaders.at(index);
quint32 mode = readUInt(header.h.external_file_attributes); quint32 mode = readUInt(header.h.external_file_attributes);
const HostOS hostOS = HostOS(readUShort(header.h.version_made) >> 8); const HostOS hostOS = HostOS(readUShort(header.h.version_made) >> 8);
@ -478,7 +479,7 @@ void QZipPrivate::fillFileInfo(int index, QZipReader::FileInfo &fileInfo) const
break; break;
default: default:
qWarning("QZip: Zip entry format at %d is not supported.", index); qWarning("QZip: Zip entry format at %d is not supported.", index);
return; // we don't support anything else return fileInfo; // we don't support anything else
} }
ushort general_purpose_bits = readUShort(header.h.general_purpose_bits); ushort general_purpose_bits = readUShort(header.h.general_purpose_bits);
@ -495,6 +496,8 @@ void QZipPrivate::fillFileInfo(int index, QZipReader::FileInfo &fileInfo) const
fileInfo.filePath = fileInfo.filePath.mid(1); fileInfo.filePath = fileInfo.filePath.mid(1);
while (!fileInfo.filePath.isEmpty() && fileInfo.filePath.at(fileInfo.filePath.size() - 1) == QLatin1Char('/')) while (!fileInfo.filePath.isEmpty() && fileInfo.filePath.at(fileInfo.filePath.size() - 1) == QLatin1Char('/'))
fileInfo.filePath.chop(1); fileInfo.filePath.chop(1);
return fileInfo;
} }
class QZipReaderPrivate : public QZipPrivate class QZipReaderPrivate : public QZipPrivate
@ -895,11 +898,8 @@ QVector<QZipReader::FileInfo> QZipReader::fileInfoList() const
QVector<FileInfo> files; QVector<FileInfo> files;
const int numFileHeaders = d->fileHeaders.size(); const int numFileHeaders = d->fileHeaders.size();
files.reserve(numFileHeaders); files.reserve(numFileHeaders);
for (int i = 0; i < numFileHeaders; ++i) { for (int i = 0; i < numFileHeaders; ++i)
QZipReader::FileInfo fi; files.append(d->fillFileInfo(i));
d->fillFileInfo(i, fi);
files.append(fi);
}
return files; return files;
} }
@ -923,10 +923,9 @@ int QZipReader::count() const
QZipReader::FileInfo QZipReader::entryInfoAt(int index) const QZipReader::FileInfo QZipReader::entryInfoAt(int index) const
{ {
d->scanFiles(); d->scanFiles();
QZipReader::FileInfo fi;
if (index >= 0 && index < d->fileHeaders.count()) if (index >= 0 && index < d->fileHeaders.count())
d->fillFileInfo(index, fi); return d->fillFileInfo(index);
return fi; return QZipReader::FileInfo();
} }
/*! /*!