summaryrefslogtreecommitdiff
path: root/lib/compression/lzxpress.c
diff options
context:
space:
mode:
authorJoseph Sutton <josephsutton@catalyst.net.nz>2022-03-08 12:27:10 +1300
committerAndrew Bartlett <abartlet@samba.org>2022-05-12 02:22:35 +0000
commit075df819cce783d69069943f39bead833f3628ef (patch)
treefe7283305aa4567a4ea8cee589f6c9c1e58efbdf /lib/compression/lzxpress.c
parent877f007f32d2cee8944b747be988cc062d13d5c0 (diff)
downloadsamba-075df819cce783d69069943f39bead833f3628ef.tar.gz
compression: Move maximum length calculation out of inner loop
This makes the code clearer. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'lib/compression/lzxpress.c')
-rw-r--r--lib/compression/lzxpress.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/compression/lzxpress.c b/lib/compression/lzxpress.c
index 6233e4072ac..de062872560 100644
--- a/lib/compression/lzxpress.c
+++ b/lib/compression/lzxpress.c
@@ -85,20 +85,17 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed,
(compressed_pos < max_compressed_size)) {
bool found = false;
- uint32_t max_offset = uncompressed_pos;
-
uint32_t best_len = 2;
uint32_t best_offset = 0;
int32_t offset;
- max_offset = MIN(0x2000, max_offset);
+ const uint32_t max_offset = MIN(0x2000, uncompressed_pos);
+ /* maximum len we can encode into metadata */
+ const uint32_t max_len = MIN(0xFFFF + 3, uncompressed_size - uncompressed_pos);
/* search for the longest match in the window for the lookahead buffer */
for (offset = 1; (uint32_t)offset <= max_offset; offset++) {
- /* maximum len we can encode into metadata */
- const uint32_t max_len = MIN(0xFFFF + 3, uncompressed_size - uncompressed_pos);
-
uint32_t len;
for (len = 0;