From: Yann Collet Date: Mon, 20 Jun 2016 14:18:19 +0000 (+0200) Subject: roundTripCrash automatic compression level now depends on first 128 bytes X-Git-Tag: v0.7.1~2^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbf8c52954db5f442e9da873be367853125101fa;p=thirdparty%2Fzstd.git roundTripCrash automatic compression level now depends on first 128 bytes --- diff --git a/programs/roundTripCrash.c b/programs/roundTripCrash.c index 1b6e1d7b4..d5b673f44 100644 --- a/programs/roundTripCrash.c +++ b/programs/roundTripCrash.c @@ -36,8 +36,14 @@ #include /* fprintf */ #include /* stat */ #include /* stat */ +#include "xxhash.h" #include "zstd.h" +/*=========================================== +* Macros +*==========================================*/ +#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) + /** roundTripTest() : * Compresses `srcBuff` into `compressedBuff`, * then decompresses `compressedBuff` into `resultBuff`. @@ -51,7 +57,9 @@ static size_t roundTripTest(void* resultBuff, size_t resultBuffCapacity, const void* srcBuff, size_t srcBuffSize) { static const int maxClevel = 19; - int const cLevel = (!srcBuffSize) ? 1 : (*(const unsigned char*)srcBuff) % maxClevel; + size_t const hashLength = MIN(128, srcBuffSize); + unsigned const h32 = XXH32(srcBuff, hashLength, 0); + int const cLevel = h32 % maxClevel; size_t const cSize = ZSTD_compress(compressedBuff, compressedBuffCapacity, srcBuff, srcBuffSize, cLevel); if (ZSTD_isError(cSize)) { fprintf(stderr, "Compression error : %s \n", ZSTD_getErrorName(cSize));