static size_t ZSTD_optimalBlockSize(const void* src, size_t srcSize, size_t blockSizeMax, ZSTD_strategy strat, S64 savings)
{
- if (srcSize <= 128 KB || blockSizeMax < 128 KB)
- return MIN(srcSize, blockSizeMax);
- (void)strat;
if (strat >= ZSTD_btlazy2)
return ZSTD_splitBlock_4k(src, srcSize, blockSizeMax);
+ if (srcSize <= 128 KB || blockSizeMax < 128 KB)
+ return MIN(srcSize, blockSizeMax);
/* blind split strategy
- * heuristic, just tested as being "generally better"
- * do not split incompressible data though: just respect the 3 bytes per block overhead limit.
+ * no cpu cost, but can over-split homegeneous data.
+ * heuristic, tested as being "generally better".
+ * do not split incompressible data though: respect the 3 bytes per block overhead limit.
*/
return savings ? 92 KB : 128 KB;
}
ZSTD_freeDCtx(dctx);
}
- /* long rle test */
+ /* rle detection test: must compress better blocks with a single identical byte repeated */
{ size_t sampleSize = 0;
- size_t expectedCompressedSize = 39; /* block 1, 2: compressed, block 3: RLE, zstd 1.4.4 */
- DISPLAYLEVEL(3, "test%3i : Long RLE test : ", testNb++);
- memset((char*)CNBuffer+sampleSize, 'B', 256 KB - 1);
- sampleSize += 256 KB - 1;
- memset((char*)CNBuffer+sampleSize, 'A', 96 KB);
- sampleSize += 96 KB;
+ size_t maxCompressedSize = 46; /* block 1, 2: compressed, block 3: RLE, zstd 1.4.4 */
+ DISPLAYLEVEL(3, "test%3i : RLE detection test : ", testNb++);
+ memset((char*)CNBuffer+sampleSize, 'B', 256 KB - 2);
+ sampleSize += 256 KB - 2;
+ memset((char*)CNBuffer+sampleSize, 'A', 100 KB);
+ sampleSize += 100 KB;
cSize = ZSTD_compress(compressedBuffer, ZSTD_compressBound(sampleSize), CNBuffer, sampleSize, 1);
- if (ZSTD_isError(cSize) || cSize > expectedCompressedSize) goto _output_error;
+ if (ZSTD_isError(cSize) || cSize > maxCompressedSize) {
+ DISPLAYLEVEL(4, "error: cSize %u > %u expected ! \n", (unsigned)cSize, (unsigned)maxCompressedSize);
+ goto _output_error;
+ }
{ CHECK_NEWV(regenSize, ZSTD_decompress(decodedBuffer, sampleSize, compressedBuffer, cSize));
if (regenSize!=sampleSize) goto _output_error; }
DISPLAYLEVEL(3, "OK \n");