Re-use string holding file contents

This should reduce memory allocations while walking through an archive's
files.
This commit is contained in:
Martchus 2023-06-05 20:52:45 +02:00
parent 524b16815a
commit 671c45aae5
1 changed files with 2 additions and 1 deletions

View File

@ -43,6 +43,7 @@ void walkThroughArchiveInternal(struct archive *ar, const string &archiveName, c
{
// iterate through all archive entries
struct archive_entry *const entry = archive_entry_new();
auto fileContent = std::string();
while (archive_read_next_header2(ar, entry) == ARCHIVE_OK) {
// check entry type (only dirs, files and symlinks relevant here)
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
const la_int64_t fileSize = archive_entry_size(entry);
std::string fileContent;
fileContent.clear();
if (fileSize > 0) {
fileContent.reserve(static_cast<string::size_type>(fileSize));
}