aboutsummaryrefslogtreecommitdiff
path: root/src/xz/coder.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2013-06-21 21:50:26 +0300
committerLasse Collin <lasse.collin@tukaani.org>2013-06-26 10:54:18 +0300
commit45edf2966fc9a4d2eae8f84b2fa027fb4fa1df8b (patch)
tree0425b0713325ebb6a1b46e622bc026f93f377b38 /src/xz/coder.c
parentxz: Change size_t to uint32_t in a few places. (diff)
downloadxz-45edf2966fc9a4d2eae8f84b2fa027fb4fa1df8b.tar.xz
xz: Fix interaction between preset and custom filter chains.
There was somewhat illogical behavior when --extreme was specified and mixed with custom filter chains. Before this commit, "xz -9 --lzma2 -e" was equivalent to "xz --lzma2". After it is equivalent to "xz -6e" (all earlier preset options get forgotten when a custom filter chain is specified and the default preset is 6 to which -e is applied). I find this less illogical. This also affects the meaning of "xz -9e --lzma2 -7". Earlier it was equivalent to "xz -7e" (the -e specified before a custom filter chain wasn't forgotten). Now it is "xz -7". Note that "xz -7e" still is the same as "xz -e7". Hopefully very few cared about this in the first place, so pretty much no one should even notice this change. Thanks to Conley Moorhous.
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 f5d372aa..e0867e2a 100644
--- a/src/xz/coder.c
+++ b/src/xz/coder.c
@@ -40,12 +40,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;
@@ -63,11 +58,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) {
@@ -81,9 +74,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;
}
@@ -98,6 +102,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;
}
@@ -134,9 +144,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();