From 636f28c310ebba67f8e0d315016b9e45db139c1e Mon Sep 17 00:00:00 2001 From: Jerem584 <31523935+Jerem584@users.noreply.github.com> Date: Sun, 25 Dec 2022 17:34:55 +0100 Subject: [PATCH 1/2] From 4000ms+ zip loading time to ~60-100ms --- zip_file.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zip_file.hpp b/zip_file.hpp index c324f70..49daefa 100644 --- a/zip_file.hpp +++ b/zip_file.hpp @@ -5183,7 +5183,10 @@ class zip_file void load(std::istream &stream) { reset(); - buffer_.assign(std::istreambuf_iterator(stream), std::istreambuf_iterator()); + stream.seekg(0, std::ios::end); + buffer_.resize(stream.tellg()); + stream.seekg(0); + stream.read(buffer_.data(), buffer_.size()); remove_comment(); start_read(); } From 9a816cc9d861a4c43c0781b72b55aad4b816576f Mon Sep 17 00:00:00 2001 From: Jerem584 <31523935+Jerem584@users.noreply.github.com> Date: Sun, 25 Dec 2022 17:40:11 +0100 Subject: [PATCH 2/2] Bypass windows.h min/max macro --- zip_file.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zip_file.hpp b/zip_file.hpp index c324f70..feafb62 100644 --- a/zip_file.hpp +++ b/zip_file.hpp @@ -5621,7 +5621,7 @@ class zip_file { if(!comment.empty()) { - auto comment_length = std::min(static_cast(comment.length()), std::numeric_limits::max()); + auto comment_length = (std::min)(static_cast(comment.length()), (std::numeric_limits::max)()); buffer_[buffer_.size() - 2] = static_cast(comment_length); buffer_[buffer_.size() - 1] = static_cast(comment_length >> 8); std::copy(comment.begin(), comment.end(), std::back_inserter(buffer_));