From 4dfe9d52e98299021341cbf6dd4101c5579d734d Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 20 Nov 2006 09:40:46 +0100 Subject: [PATCH] Don't be too strict when checking the compression ratio (sf.net feature request #1596111). --- src/packer.cpp | 41 +++++++++++++++++++---------------------- src/packer.h | 1 + 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/packer.cpp b/src/packer.cpp index 3ea013fb..556afbe0 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -274,41 +274,38 @@ bool Packer::compress(upx_bytep in, upx_bytep out, #endif -bool Packer::checkCompressionRatio(unsigned u_len, unsigned c_len) const +bool Packer::checkDefaultCompressionRatio(unsigned u_len, unsigned c_len) const { assert((int)u_len > 0); assert((int)c_len > 0); - -#if 1 - if (c_len + 512 >= u_len) // min. 512 bytes gain - return false; - if (c_len >= u_len - u_len / 8) // min. 12.5% gain - return false; -#else if (c_len >= u_len) return false; -#endif + unsigned gain = u_len - c_len; + + if (gain < 512) // need at least 512 bytes gain + return false; +#if 1 + if (gain >= 4096) // ok if we have 4096 bytes gain + return true; + if (c_len >= u_len - u_len / 8) // ok if we have 12.5% gain + return true; + return false; +#else return true; +#endif } +bool Packer::checkCompressionRatio(unsigned u_len, unsigned c_len) const +{ + return checkDefaultCompressionRatio(u_len, c_len); +} + bool Packer::checkFinalCompressionRatio(const OutputFile *fo) const { const unsigned u_len = file_size; const unsigned c_len = fo->getBytesWritten(); - - assert((int)u_len > 0); - assert((int)c_len > 0); - - if (c_len + 4096 <= u_len) // ok if we have 4096 bytes gain - return true; - - if (c_len + 512 >= u_len) // min. 512 bytes gain - return false; - if (c_len >= u_len - u_len / 8) // min. 12.5% gain - return false; - - return true; + return checkDefaultCompressionRatio(u_len, c_len); } diff --git a/src/packer.h b/src/packer.h index 0771acdb..b7b836bf 100644 --- a/src/packer.h +++ b/src/packer.h @@ -171,6 +171,7 @@ protected: const upx_compress_config_t *cconf = NULL); virtual void decompress(const upx_bytep in, upx_bytep out, bool verify_checksum = true, Filter *ft = NULL); + virtual bool checkDefaultCompressionRatio(unsigned u_len, unsigned c_len) const; virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const; virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;