From 2f7463b76b4c538bdd105475c12839f0eef7ec23 Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Mon, 20 Nov 2023 14:26:14 +0100 Subject: [PATCH] SporeModManager: use global std::vector() buffer in Zip.cpp --- SporeModManager/SporeModManagerHelpers/Zip.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/SporeModManager/SporeModManagerHelpers/Zip.cpp b/SporeModManager/SporeModManagerHelpers/Zip.cpp index dca1ae7..be0140f 100644 --- a/SporeModManager/SporeModManagerHelpers/Zip.cpp +++ b/SporeModManager/SporeModManagerHelpers/Zip.cpp @@ -28,6 +28,7 @@ using namespace SporeModManagerHelpers; // static std::map l_ZipFileStreams; +static std::vector l_ZipFileBuffer(UNZIP_READ_SIZE); // // Local Functions @@ -133,7 +134,6 @@ bool Zip::CloseFile(ZipFile zipFile) bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesystem::path outputFile) { - static std::vector buffer(UNZIP_READ_SIZE); int bytesRead = 0; std::ofstream outputFileStream; @@ -159,7 +159,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst do { - bytesRead = unzReadCurrentFile(zipFile, buffer.data(), UNZIP_READ_SIZE); + bytesRead = unzReadCurrentFile(zipFile, l_ZipFileBuffer.data(), UNZIP_READ_SIZE); if (bytesRead < 0) { unzCloseCurrentFile(zipFile); @@ -168,7 +168,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst } else if (bytesRead > 0) { - outputFileStream.write(buffer.data(), bytesRead); + outputFileStream.write(l_ZipFileBuffer.data(), bytesRead); } } while (bytesRead > 0); @@ -180,7 +180,6 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::vector& outBuffer) { - static std::vector buffer(UNZIP_READ_SIZE); int bytesRead = 0; // try to find file in zip @@ -200,7 +199,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::vector 0) { - outBuffer.insert(outBuffer.end(), buffer.begin(), std::next(buffer.begin(), bytesRead)); + outBuffer.insert(outBuffer.end(), l_ZipFileBuffer.begin(), l_ZipFileBuffer.begin() + bytesRead); } } while (bytesRead > 0);