X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;ds=sidebyside;f=include%2Fwimlib%2Flz_extend.h;h=bd00183b973d980b5eab3f1aa2acf4b263e18569;hb=f50557a7095444c554a066b3837c2999ecd1be31;hp=e9a56224ea0768104838576815c43d58179bf545;hpb=0ecb0529b5fcacc1abafa1f3f02a40c44783ada8;p=wimlib diff --git a/include/wimlib/lz_extend.h b/include/wimlib/lz_extend.h index e9a56224..bd00183b 100644 --- a/include/wimlib/lz_extend.h +++ b/include/wimlib/lz_extend.h @@ -3,6 +3,9 @@ * * Fast match extension for Lempel-Ziv matchfinding. * + * Author: Eric Biggers + * Year: 2014, 2015 + * * The author dedicates this file to the public domain. * You can do whatever you want with this file. */ @@ -20,11 +23,10 @@ lz_extend(const u8 * const strptr, const u8 * const matchptr, const u32 start_len, const u32 max_len) { u32 len = start_len; + machine_word_t v_word; if (UNALIGNED_ACCESS_IS_FAST) { - machine_word_t v_word; - if (likely(max_len - len >= 4 * WORDSIZE)) { #define COMPARE_WORD_STEP \ @@ -48,18 +50,18 @@ lz_extend(const u8 * const strptr, const u8 * const matchptr, goto word_differs; len += WORDSIZE; } + } - while (len < max_len && matchptr[len] == strptr[len]) - len++; - return len; + while (len < max_len && matchptr[len] == strptr[len]) + len++; + return len; - word_differs: - return len + (ffsw(v_word) >> 3); - } else { - while (len < max_len && matchptr[len] == strptr[len]) - len++; - return len; - } +word_differs: + if (CPU_IS_LITTLE_ENDIAN) + len += (ffsw(v_word) >> 3); + else + len += (flsw(v_word) >> 3); + return len; } #endif /* _WIMLIB_LZ_EXTEND_H */