diff --git a/lib/compress/hist.c b/lib/compress/hist.c index 3692bc250cadbb831133b432094a7115efed848e..cf4a169f13df4272011f2974f00e5836ec0fb484 100644 --- a/lib/compress/hist.c +++ b/lib/compress/hist.c @@ -36,7 +36,19 @@ void HIST_add(unsigned* count, const void* src, size_t srcSize) { const BYTE* ip = (const BYTE*)src; const BYTE* const end = ip + srcSize; - + const BYTE* const bulkEnd = ip + (srcSize & ~(size_t)7); + + while (ip < bulkEnd) { + count[ip[ 0]]++; + count[ip[ 1]]++; + count[ip[ 2]]++; + count[ip[ 3]]++; + count[ip[ 4]]++; + count[ip[ 5]]++; + count[ip[ 6]]++; + count[ip[ 7]]++; + ip += 8; + } while (ipmaxNbLit <= 128 KB); assert(seqStorePtr->lit + litLength <= seqStorePtr->litStart + seqStorePtr->maxNbLit); assert(literals + litLength <= litLimit); - if (litEnd <= litLimit_w) { - /* Common case we can use wildcopy. - * First copy 16 bytes, because literals are likely short. - */ - ZSTD_STATIC_ASSERT(WILDCOPY_OVERLENGTH >= 16); - ZSTD_copy16(seqStorePtr->lit, literals); - if (litLength > 16) { - ZSTD_wildcopy(seqStorePtr->lit+16, literals+16, litLength-16, ZSTD_no_overlap); + if (LIKELY(litLength != 0)) { + if (litEnd <= litLimit_w) { + /* Common case we can use wildcopy. + * First copy 16 bytes, because literals are likely short. + */ + ZSTD_STATIC_ASSERT(WILDCOPY_OVERLENGTH >= 16); + ZSTD_copy16(seqStorePtr->lit, literals); + if (litLength > 16) { + ZSTD_wildcopy(seqStorePtr->lit+16, literals+16, litLength-16, ZSTD_no_overlap); + } + } else { + ZSTD_safecopyLiterals(seqStorePtr->lit, literals, litEnd, litLimit_w); } - } else { - ZSTD_safecopyLiterals(seqStorePtr->lit, literals, litEnd, litLimit_w); } seqStorePtr->lit += litLength;