]> wimlib.net Git - wimlib/commitdiff
lzma hash lzma_hash
authorEric Biggers <ebiggers3@gmail.com>
Sun, 3 Jul 2016 23:51:12 +0000 (18:51 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 3 Jul 2016 23:51:12 +0000 (18:51 -0500)
include/wimlib/bt_matchfinder.h
src/lzx_compress.c
src/xpress_compress.c

index 0188f774874a57f8bcf390b55e079377ac96799f..f71e7bd059653c7518aca74aa22293754d63b40f 100644 (file)
@@ -84,6 +84,21 @@ struct lz_match {
        u32 offset;
 };
 
+static u32 crc[256];
+
+#define kCrcPoly 0xEDB88320
+
+static void crc_init(void)
+{
+       for (u32 i = 0; i < 256; i++) {
+               u32 r = i;
+               unsigned j;
+               for (j = 0; j < 8; j++)
+                       r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
+               crc[i] = r;
+       }
+}
+
 #endif /* _WIMLIB_BT_MATCHFINDER_H */
 
 struct TEMPLATED(bt_matchfinder) {
@@ -181,11 +196,13 @@ TEMPLATED(bt_matchfinder_advance_one_byte)(struct TEMPLATED(bt_matchfinder) * co
        seq2 = loaded_u32_to_u16(seq4);
 #endif
 
-       hash4 = lz_hash(seq4, BT_MATCHFINDER_HASH4_ORDER);
-       hash3 = lz_hash(seq3, BT_MATCHFINDER_HASH3_ORDER);
+       u32 temp = crc[in_next[0]] ^ in_next[1];
 #ifdef BT_MATCHFINDER_HASH2_ORDER
-       hash2 = lz_hash(seq2, BT_MATCHFINDER_HASH2_ORDER);
+       hash2 = temp & ((1 << BT_MATCHFINDER_HASH2_ORDER) - 1);
 #endif
+       temp ^= ((u32)in_next[2] << 8);
+       hash3 = temp & ((1 << BT_MATCHFINDER_HASH3_ORDER) - 1);
+       hash4 = (temp ^ (crc[in_next[3]] << 5)) & ((1 << BT_MATCHFINDER_HASH4_ORDER) - 1);
 
 #ifdef BT_MATCHFINDER_HASH2_ORDER
        cur_node = mf->hash2_tab[hash2];
index f0c3c5268c82c5e26347b9c42e5c008e811886c8..6d9f1ce53dc174e024de0ec6841dae3725dfc932 100644 (file)
@@ -2890,6 +2890,8 @@ lzx_create_compressor(size_t max_bufsize, unsigned compression_level,
        /* Prepare the offset => offset slot mapping. */
        lzx_init_offset_slot_tabs(c);
 
+       crc_init();
+
        *c_ret = c;
        return 0;
 
index d8cb7697deb9732eeab7a4e33c1d6093abb618fc..b5b9e28b01d1c652abf1b33f03120a868a21933a 100644 (file)
@@ -1133,6 +1133,8 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level,
        if (c->max_search_depth < 1)
                c->max_search_depth = 1;
 
+       crc_init();
+
        *c_ret = c;
        return 0;