From 9d452fc5d1523ca8a6d3ce42a8eff58d1a791ba2 Mon Sep 17 00:00:00 2001 From: wizou Date: Thu, 17 Jun 2010 15:56:42 +0000 Subject: [PATCH] Improving compression performance (avoiding unnecessary file flush and better handling the 2GB limit) git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6109 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/build.cpp | 7 +++---- Source/mmap.cpp | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/build.cpp b/Source/build.cpp index 9b1e7bb5..52a917c8 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -794,9 +794,8 @@ int CEXEBuild::add_db_data(IMMap *mmap) // returns offset { // grow datablock so that there is room to compress into int bufferlen = length + 1024 + length / 4; // give a nice 25% extra space - if (bufferlen < 0) // too much data... try allocating as much as possible - db->resize(max(st, 0x7fffffff)); - else + if (st+bufferlen+sizeof(int) < 0) // we've hit a signed integer overflow (file is over 1.6 GB) + bufferlen = INT_MAX-st-sizeof(int); // so maximize compressor room and hope the file compresses well db->resize(st + bufferlen + sizeof(int)); int n = compressor->Init(build_compress_level, build_compress_dict_size); @@ -2354,7 +2353,7 @@ int CEXEBuild::UpdatePEHeader() void CEXEBuild::set_default_output_filename(const tstring& filename) { - if (build_output_filename[0] == 0) + if (build_output_filename[0] == 0) _tcsnccpy(build_output_filename,filename.c_str(),1024-1); } diff --git a/Source/mmap.cpp b/Source/mmap.cpp index 29623933..787bc6be 100644 --- a/Source/mmap.cpp +++ b/Source/mmap.cpp @@ -336,7 +336,7 @@ void MMapFile::flush(int num) { if (m_pView) #ifdef _WIN32 - FlushViewOfFile(m_pView, num); + {} // improving performance by commenting: FlushViewOfFile(m_pView, num); #else msync((char *)m_pView, num, MS_SYNC); #endif @@ -431,6 +431,8 @@ void MMapBuf::resize(int newlen) if (newlen > m_alloc) { m_alloc = newlen + (16 << 20); // add 16mb to top of mapping + if (m_alloc < 0) // we've hit a signed integer overflow + m_alloc = INT_MAX; m_fm.resize(m_alloc);