From 075df819cce783d69069943f39bead833f3628ef Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Tue, 8 Mar 2022 12:27:10 +1300 Subject: compression: Move maximum length calculation out of inner loop This makes the code clearer. Signed-off-by: Joseph Sutton Reviewed-by: Douglas Bagnall --- lib/compression/lzxpress.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'lib/compression/lzxpress.c') 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; -- cgit v1.2.1