diff --git a/coding/zip_creator.cpp b/coding/zip_creator.cpp index 05121112bf..20a2af6e14 100644 --- a/coding/zip_creator.cpp +++ b/coding/zip_creator.cpp @@ -13,6 +13,7 @@ #include "../../std/vector.hpp" #include "../../std/ctime.hpp" #include "../../std/algorithm.hpp" +#include "../../std/unique_ptr.hpp" #include "../../3party/zlib/contrib/minizip/zip.h" @@ -57,11 +58,7 @@ void CreateTMZip(tm_zip & res) bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, string const & zipFilePath) { - /// Prepare buffer at the very beginning to avoid clang 3.5, loop optimization. - /// @todo Need to check with the new XCode (and clang) update. - - size_t const bufSize = ZIP_FILE_BUFFER_SIZE; - vector buffer(bufSize); + unique_ptr buffer(new char[ZIP_FILE_BUFFER_SIZE]); // 2. Open zip file for writing. MY_SCOPE_GUARD(outFileGuard, bind(&my::DeleteFileX, cref(zipFilePath))); @@ -93,7 +90,7 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, str size_t currSize = 0; while (currSize < fileSize) { - size_t const toRead = min(bufSize, fileSize - currSize); + size_t const toRead = min(ZIP_FILE_BUFFER_SIZE, fileSize - currSize); file.Read(currSize, &buffer[0], toRead); if (ZIP_OK != zipWriteInFileInZip(zip.Handle(), &buffer[0], toRead)) diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp index 76c733626e..df05df346b 100644 --- a/coding/zip_reader.cpp +++ b/coding/zip_reader.cpp @@ -76,11 +76,7 @@ bool ZipFileReader::IsZip(string const & zipContainer) void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileInZip, string const & outFilePath, ProgressFn progressFn) { - /// Prepare buffer at the very beginning to avoid clang 3.5, loop optimization. - /// @todo Need to check with the new XCode (and clang) update. - - size_t const bufSize = ZIP_FILE_BUFFER_SIZE; - vector buf(bufSize); + unique_ptr buf(new char[ZIP_FILE_BUFFER_SIZE]); unzFile zip = unzOpen64(zipContainer.c_str()); if (!zip) @@ -106,7 +102,7 @@ void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileIn uint64_t pos = 0; while (true) { - int const readBytes = unzReadCurrentFile(zip, &buf[0], bufSize); + int const readBytes = unzReadCurrentFile(zip, &buf[0], ZIP_FILE_BUFFER_SIZE); if (readBytes > 0) outFile.Write(&buf[0], static_cast(readBytes)); else if (readBytes < 0)