compression: Move maximum length calculation out of inner loop
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Mon, 7 Mar 2022 23:27:10 +0000 (12:27 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 12 May 2022 02:22:35 +0000 (02:22 +0000)
This makes the code clearer.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
lib/compression/lzxpress.c

index 6233e4072ac3eae59d5cfb47b1b4024379c0434c..de062872560460e0a6ff3b0b4b80cb00d797397c 100644 (file)
@@ -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;