1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 18:01:16 +02:00

Merge pull request #13175 from xokdvium/optimise-fetchtarball

libutil/tarfile: Create the scratch `std::vector` only once
This commit is contained in:
Jörg Thalheim 2025-05-13 14:21:26 +02:00 committed by GitHub
commit f0f196cef0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -178,6 +178,10 @@ time_t unpackTarfileToSink(TarArchive & archive, ExtendedFileSystemObjectSink &
{
time_t lastModified = 0;
/* Only allocate the buffer once. Use the heap because 131 KiB is a bit too
much for the stack. */
std::vector<unsigned char> buf(128 * 1024);
for (;;) {
// FIXME: merge with extract_archive
struct archive_entry * entry;
@ -212,7 +216,6 @@ time_t unpackTarfileToSink(TarArchive & archive, ExtendedFileSystemObjectSink &
crf.isExecutable();
while (true) {
std::vector<unsigned char> buf(128 * 1024);
auto n = archive_read_data(archive.archive, buf.data(), buf.size());
if (n < 0)
checkLibArchive(archive.archive, n, "cannot read file from tarball: %s");