aboutsummaryrefslogtreecommitdiff
path: root/src/xz/coder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xz/coder.c')
-rw-r--r--src/xz/coder.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/xz/coder.c b/src/xz/coder.c
index a98be97f..54864506 100644
--- a/src/xz/coder.c
+++ b/src/xz/coder.c
@@ -43,12 +43,7 @@ static io_buf out_buf;
static uint32_t filters_count = 0;
/// Number of the preset (0-9)
-static uint32_t preset_number = 6;
-
-/// If a preset is used (no custom filter chain) and preset_extreme is true,
-/// a significantly slower compression is used to achieve slightly better
-/// compression ratio.
-static bool preset_extreme = false;
+static uint32_t preset_number = LZMA_PRESET_DEFAULT;
/// Integrity check type
static lzma_check check;
@@ -74,11 +69,9 @@ coder_set_check(lzma_check new_check)
}
-extern void
-coder_set_preset(uint32_t new_preset)
+static void
+forget_filter_chain(void)
{
- preset_number = new_preset;
-
// Setting a preset makes us forget a possibly defined custom
// filter chain.
while (filters_count > 0) {
@@ -92,9 +85,20 @@ coder_set_preset(uint32_t new_preset)
extern void
+coder_set_preset(uint32_t new_preset)
+{
+ preset_number &= ~LZMA_PRESET_LEVEL_MASK;
+ preset_number |= new_preset;
+ forget_filter_chain();
+ return;
+}
+
+
+extern void
coder_set_extreme(void)
{
- preset_extreme = true;
+ preset_number |= LZMA_PRESET_EXTREME;
+ forget_filter_chain();
return;
}
@@ -109,6 +113,12 @@ coder_add_filter(lzma_vli id, void *options)
filters[filters_count].options = options;
++filters_count;
+ // Setting a custom filter chain makes us forget the preset options.
+ // This makes a difference if one specifies e.g. "xz -9 --lzma2 -e"
+ // where the custom filter chain resets the preset level back to
+ // the default 6, making the example equivalent to "xz -6e".
+ preset_number = LZMA_PRESET_DEFAULT;
+
return;
}
@@ -154,9 +164,6 @@ coder_set_compression_settings(void)
}
// Get the preset for LZMA1 or LZMA2.
- if (preset_extreme)
- preset_number |= LZMA_PRESET_EXTREME;
-
if (lzma_lzma_preset(&opt_lzma, preset_number))
message_bug();