mirror of https://github.com/upx/upx.git
Clean up OptVar handling.
This commit is contained in:
parent
05e44b9644
commit
e6edad8f46
|
@ -43,8 +43,6 @@
|
|||
|
||||
void lzma_compress_config_t::reset()
|
||||
{
|
||||
mem_clear(this, sizeof(*this));
|
||||
|
||||
pos_bits.reset();
|
||||
lit_pos_bits.reset();
|
||||
lit_context_bits.reset();
|
||||
|
@ -111,11 +109,11 @@ static int prepare(lzma_compress_result_t *res,
|
|||
res->num_fast_bytes = 64; // 5 .. 273
|
||||
res->match_finder_cycles = 0;
|
||||
// UPX overrides
|
||||
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value_c;
|
||||
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
|
||||
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value_c;
|
||||
res->dict_size = lzma_compress_config_t::dict_size_t::default_value_c;
|
||||
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
|
||||
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value;
|
||||
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value;
|
||||
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value;
|
||||
res->dict_size = lzma_compress_config_t::dict_size_t::default_value;
|
||||
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value;
|
||||
// method overrides
|
||||
if (method >= 0x100) {
|
||||
res->pos_bits = (method >> 16) & 15;
|
||||
|
@ -201,6 +199,12 @@ static int prepare(lzma_compress_result_t *res,
|
|||
}
|
||||
}
|
||||
|
||||
lzma_compress_config_t::pos_bits_t::assertValue(res->pos_bits);
|
||||
lzma_compress_config_t::lit_pos_bits_t::assertValue(res->lit_pos_bits);
|
||||
lzma_compress_config_t::lit_context_bits_t::assertValue(res->lit_context_bits);
|
||||
lzma_compress_config_t::dict_size_t::assertValue(res->dict_size);
|
||||
lzma_compress_config_t::num_fast_bytes_t::assertValue(res->num_fast_bytes);
|
||||
|
||||
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
return 0;
|
||||
|
|
27
src/conf.h
27
src/conf.h
|
@ -480,24 +480,27 @@ struct upx_callback_t
|
|||
// compression - config_t
|
||||
**************************************************************************/
|
||||
|
||||
template <class T, T default_value, T min_value, T max_value>
|
||||
template <class T, T default_value_, T min_value_, T max_value_>
|
||||
struct OptVar
|
||||
{
|
||||
typedef T value_type;
|
||||
static const T default_value_c = default_value;
|
||||
static const T min_value_c = min_value;
|
||||
static const T max_value_c = max_value;
|
||||
static const T default_value = default_value_;
|
||||
static const T min_value = min_value_;
|
||||
static const T max_value = max_value_;
|
||||
|
||||
void assertValue() const {
|
||||
static void assertValue(const T &v) {
|
||||
// info: this generates annoying warnings "unsigned >= 0 is always true"
|
||||
//assert(v >= min_value_c);
|
||||
assert(v == min_value_c || v >= min_value_c + 1);
|
||||
assert(v <= max_value_c);
|
||||
//assert(v >= min_value);
|
||||
assert(v == min_value || v >= min_value + 1);
|
||||
assert(v <= max_value);
|
||||
}
|
||||
void assertValue() const {
|
||||
assertValue(v);
|
||||
}
|
||||
|
||||
OptVar() : v(default_value), is_set(0) { }
|
||||
OptVar& operator= (const T other) {
|
||||
v = other; is_set += 1;
|
||||
OptVar& operator= (const T &other) {
|
||||
v = other; is_set = 1;
|
||||
assertValue();
|
||||
return *this;
|
||||
}
|
||||
|
@ -513,10 +516,10 @@ struct OptVar
|
|||
// optional assignments
|
||||
template <class T, T a, T b, T c>
|
||||
inline void oassign(OptVar<T,a,b,c> &self, const OptVar<T,a,b,c> &other) {
|
||||
if (other.is_set) { self.v = other.v; self.is_set += 1; }
|
||||
if (other.is_set) { self.v = other.v; self.is_set = 1; }
|
||||
}
|
||||
template <class T, T a, T b, T c>
|
||||
inline void oassign(unsigned &v, const OptVar<T,a,b,c> &other) {
|
||||
inline void oassign(T &v, const OptVar<T,a,b,c> &other) {
|
||||
if (other.is_set) { v = other.v; }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue