From e2d7d08888f915667c94e6dbbadaee38a5d50fa5 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 3 Sep 2024 16:52:10 -0700 Subject: [PATCH] use ZSTD_memset() for better portability on Linux kernel --- lib/compress/zstd_preSplit.c | 50 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/lib/compress/zstd_preSplit.c b/lib/compress/zstd_preSplit.c index bba348927..8db742c4d 100644 --- a/lib/compress/zstd_preSplit.c +++ b/lib/compress/zstd_preSplit.c @@ -39,38 +39,42 @@ typedef struct { static FingerPrint pastEvents; static FingerPrint newEvents; -static void initStats(void) { - memset(&pastEvents, 0, sizeof(pastEvents)); - memset(&newEvents, 0, sizeof(newEvents)); +static void initStats(void) +{ + ZSTD_memset(&pastEvents, 0, sizeof(pastEvents)); + ZSTD_memset(&newEvents, 0, sizeof(newEvents)); } /* ==================================== */ -static void addToFingerprint(FingerPrint* fp, const void* src, size_t s) { - const char* p = src; - size_t limit = s - HASHLENGTH + 1; - size_t n; - assert(s >= HASHLENGTH); - for (n = 0; n < limit; n++) { - fp->events[hash2(p++)]++; - } - fp->nbEvents += limit; +static void addToFingerprint(FingerPrint* fp, const void* src, size_t s) +{ + const char* p = src; + size_t limit = s - HASHLENGTH + 1; + size_t n; + assert(s >= HASHLENGTH); + for (n = 0; n < limit; n++) { + fp->events[hash2(p++)]++; + } + fp->nbEvents += limit; } -static void recordFingerprint(FingerPrint *fp, const void *src, size_t s) { - memset(fp, 0, sizeof(*fp)); - addToFingerprint(fp, src, s); +static void recordFingerprint(FingerPrint* fp, const void* src, size_t s) +{ + memset(fp, 0, sizeof(*fp)); + addToFingerprint(fp, src, s); } static S64 abs64(S64 i) { return (i < 0) ? -i : i; } -static S64 fpDistance(const FingerPrint *fp1, const FingerPrint *fp2) { - S64 distance = 0; - size_t n; - for (n = 0; n < HASHTABLESIZE; n++) { - distance += - abs64(fp1->events[n] * fp2->nbEvents - fp2->events[n] * fp1->nbEvents); - } - return distance; +static S64 fpDistance(const FingerPrint* fp1, const FingerPrint* fp2) +{ + S64 distance = 0; + size_t n; + for (n = 0; n < HASHTABLESIZE; n++) { + distance += + abs64(fp1->events[n] * fp2->nbEvents - fp2->events[n] * fp1->nbEvents); + } + return distance; } // Compare newEvents with pastEvents