lib/compression/lzhuff: add debug flag to skip LZ77
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 20 Nov 2022 21:23:53 +0000 (10:23 +1300)
committerJoseph Sutton <jsutton@samba.org>
Thu, 1 Dec 2022 22:56:39 +0000 (22:56 +0000)
Encoding without LZ77 matches is valid, and it is useful for isolating
bugs.

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

index 7a48ca73425f77ebcfa489f8885963476677bef9..ef64ea7021f30dcbf5a67d99578a3d1c6496ed23 100644 (file)
 #include "lib/util/byteorder.h"
 #include "lib/util/bytearray.h"
 
+/*
+ * DEBUG_NO_LZ77_MATCHES toggles the encoding of matches as matches. If it is
+ * false the potential match is written as a series of literals, which is a
+ * valid but usually inefficient encoding. This is useful for isolating a
+ * problem to either the LZ77 or the Huffman stage.
+ */
+#ifndef DEBUG_NO_LZ77_MATCHES
+#define DEBUG_NO_LZ77_MATCHES false
+#endif
 
 #define LZXPRESS_ERROR -1LL
 
@@ -574,7 +583,7 @@ static ssize_t lz77_encode_block(struct lzxhuff_compressor_context *cmp_ctx,
 
        j = 0;
 
-       if (remaining_size < 41) {
+       if (remaining_size < 41 || DEBUG_NO_LZ77_MATCHES) {
                /*
                 * There is no point doing a hash table and looking for
                 * matches in this tiny block (remembering we are committed to