From: Yann Collet Date: Sun, 10 Apr 2016 23:20:14 +0000 (+0200) Subject: minor refactor X-Git-Tag: v0.6.0^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c51aa6ccce7293b13a7e6b8ce36c0ac0645eec32;p=thirdparty%2Fzstd.git minor refactor --- diff --git a/programs/datagen.c b/programs/datagen.c index ad84710ba..cafbd003e 100644 --- a/programs/datagen.c +++ b/programs/datagen.c @@ -193,26 +193,26 @@ void RDG_genBuffer(void* buffer, size_t size, double matchProba, double litProba #define RDG_DICTSIZE (32 KB) #define RDG_BLOCKSIZE (128 KB) +#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) void RDG_genStdout(unsigned long long size, double matchProba, double litProba, unsigned seed) { BYTE* buff = (BYTE*)malloc(RDG_DICTSIZE + RDG_BLOCKSIZE); U64 total = 0; - size_t genBlockSize = RDG_BLOCKSIZE; - litDistribTable lt; + litDistribTable ldt; /* init */ if (buff==NULL) { fprintf(stdout, "not enough memory\n"); exit(1); } - if (litProba==0.0) litProba = matchProba / 4.5; - RDG_fillLiteralDistrib(lt, litProba); + if (litProba<=0.0) litProba = matchProba / 4.5; + RDG_fillLiteralDistrib(ldt, litProba); SET_BINARY_MODE(stdout); /* Generate initial dict */ - RDG_genBlock(buff, RDG_DICTSIZE, 0, matchProba, lt, &seed); + RDG_genBlock(buff, RDG_DICTSIZE, 0, matchProba, ldt, &seed); /* Generate compressible data */ while (total < size) { - RDG_genBlock(buff, RDG_DICTSIZE+RDG_BLOCKSIZE, RDG_DICTSIZE, matchProba, lt, &seed); - if (size-total < RDG_BLOCKSIZE) genBlockSize = (size_t)(size-total); + size_t const genBlockSize = MIN (RDG_BLOCKSIZE, size-total); + RDG_genBlock(buff, RDG_DICTSIZE+RDG_BLOCKSIZE, RDG_DICTSIZE, matchProba, ldt, &seed); total += genBlockSize; { size_t const unused = fwrite(buff, 1, genBlockSize, stdout); (void)unused; } /* update dict */