Re-use string holding file contents
This should reduce memory allocations while walking through an archive's files.
This commit is contained in:
parent
524b16815a
commit
671c45aae5
|
@ -43,6 +43,7 @@ void walkThroughArchiveInternal(struct archive *ar, const string &archiveName, c
|
||||||
{
|
{
|
||||||
// iterate through all archive entries
|
// iterate through all archive entries
|
||||||
struct archive_entry *const entry = archive_entry_new();
|
struct archive_entry *const entry = archive_entry_new();
|
||||||
|
auto fileContent = std::string();
|
||||||
while (archive_read_next_header2(ar, entry) == ARCHIVE_OK) {
|
while (archive_read_next_header2(ar, entry) == ARCHIVE_OK) {
|
||||||
// check entry type (only dirs, files and symlinks relevant here)
|
// check entry type (only dirs, files and symlinks relevant here)
|
||||||
const auto entryType(archive_entry_filetype(entry));
|
const auto entryType(archive_entry_filetype(entry));
|
||||||
|
@ -107,7 +108,7 @@ void walkThroughArchiveInternal(struct archive *ar, const string &archiveName, c
|
||||||
|
|
||||||
// determine file size to pre-allocate buffer for file content
|
// determine file size to pre-allocate buffer for file content
|
||||||
const la_int64_t fileSize = archive_entry_size(entry);
|
const la_int64_t fileSize = archive_entry_size(entry);
|
||||||
std::string fileContent;
|
fileContent.clear();
|
||||||
if (fileSize > 0) {
|
if (fileSize > 0) {
|
||||||
fileContent.reserve(static_cast<string::size_type>(fileSize));
|
fileContent.reserve(static_cast<string::size_type>(fileSize));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue