1
0
mirror of https://github.com/facebook/zstd.git synced 2025-03-07 01:10:04 +02:00

use ZSTD_memset()

for better portability on Linux kernel
This commit is contained in:
Yann Collet 2024-09-03 16:52:10 -07:00
parent 586ca96fec
commit e2d7d08888

View File

@ -39,38 +39,42 @@ typedef struct {
static FingerPrint pastEvents; static FingerPrint pastEvents;
static FingerPrint newEvents; static FingerPrint newEvents;
static void initStats(void) { static void initStats(void)
memset(&pastEvents, 0, sizeof(pastEvents)); {
memset(&newEvents, 0, sizeof(newEvents)); ZSTD_memset(&pastEvents, 0, sizeof(pastEvents));
ZSTD_memset(&newEvents, 0, sizeof(newEvents));
} }
/* ==================================== */ /* ==================================== */
static void addToFingerprint(FingerPrint* fp, const void* src, size_t s) { static void addToFingerprint(FingerPrint* fp, const void* src, size_t s)
const char* p = src; {
size_t limit = s - HASHLENGTH + 1; const char* p = src;
size_t n; size_t limit = s - HASHLENGTH + 1;
assert(s >= HASHLENGTH); size_t n;
for (n = 0; n < limit; n++) { assert(s >= HASHLENGTH);
fp->events[hash2(p++)]++; for (n = 0; n < limit; n++) {
} fp->events[hash2(p++)]++;
fp->nbEvents += limit; }
fp->nbEvents += limit;
} }
static void recordFingerprint(FingerPrint *fp, const void *src, size_t s) { static void recordFingerprint(FingerPrint* fp, const void* src, size_t s)
memset(fp, 0, sizeof(*fp)); {
addToFingerprint(fp, src, s); memset(fp, 0, sizeof(*fp));
addToFingerprint(fp, src, s);
} }
static S64 abs64(S64 i) { return (i < 0) ? -i : i; } static S64 abs64(S64 i) { return (i < 0) ? -i : i; }
static S64 fpDistance(const FingerPrint *fp1, const FingerPrint *fp2) { static S64 fpDistance(const FingerPrint* fp1, const FingerPrint* fp2)
S64 distance = 0; {
size_t n; S64 distance = 0;
for (n = 0; n < HASHTABLESIZE; n++) { size_t n;
distance += for (n = 0; n < HASHTABLESIZE; n++) {
abs64(fp1->events[n] * fp2->nbEvents - fp2->events[n] * fp1->nbEvents); distance +=
} abs64(fp1->events[n] * fp2->nbEvents - fp2->events[n] * fp1->nbEvents);
return distance; }
return distance;
} }
// Compare newEvents with pastEvents // Compare newEvents with pastEvents