diff options
author | vng <viktor.govako@gmail.com> | 2014-10-07 15:06:33 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:27:39 +0300 |
commit | 64a6968973dff20ed9bca485eaa2f5321861453a (patch) | |
tree | b26e78bf7504782df5ac9b080af0fdaac7fca6ea /coding/zip_reader.cpp | |
parent | f501445ddc855fbb467e768daf24811c0f6ea62e (diff) |
[iOS] Avoid clang 3.5 optimization bug (import/export kmz). Need to review in future.
Diffstat (limited to 'coding/zip_reader.cpp')
-rw-r--r-- | coding/zip_reader.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp index ffcca33951..76c733626e 100644 --- a/coding/zip_reader.cpp +++ b/coding/zip_reader.cpp @@ -4,6 +4,7 @@ #include "../base/logging.hpp" #include "../coding/file_writer.hpp" +#include "../coding/constants.hpp" #include "../std/bind.hpp" @@ -75,6 +76,12 @@ 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<char> buf(bufSize); + unzFile zip = unzOpen64(zipContainer.c_str()); if (!zip) MYTHROW(OpenZipException, ("Can't get zip file handle", zipContainer)); @@ -91,9 +98,6 @@ void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileIn if (UNZ_OK != unzGetCurrentFileInfo64(zip, &fileInfo, NULL, 0, NULL, 0, NULL, 0)) MYTHROW(LocateZipException, ("Can't get uncompressed file size inside zip", fileInZip)); - size_t const BUF_SIZE = 1024 * 50; - vector<char> buf(BUF_SIZE); - // First outFile should be closed, then FileWriter::DeleteFileX is called, // so make correct order of guards. MY_SCOPE_GUARD(outFileGuard, bind(&FileWriter::DeleteFileX, cref(outFilePath))); @@ -102,7 +106,7 @@ void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileIn uint64_t pos = 0; while (true) { - int const readBytes = unzReadCurrentFile(zip, &buf[0], BUF_SIZE); + int const readBytes = unzReadCurrentFile(zip, &buf[0], bufSize); if (readBytes > 0) outFile.Write(&buf[0], static_cast<size_t>(readBytes)); else if (readBytes < 0) |