Skip to content

Commit 9269a8a

Browse files
Viq111ghatdev
authored andcommitted
Fix CompressBound to latest implementation
We have this function in Go code to not have to do a cgo call (really consuming). This function in a hot loop, that's why we can't call C code every time. This mirrors latest zstd implementation (they switched to 128kB window)
1 parent 18e8162 commit 9269a8a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

zstd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ var (
2727
// CompressBound returns the worst case size needed for a destination buffer,
2828
// which can be used to preallocate a destination buffer or select a previously
2929
// allocated buffer from a pool.
30+
// See zstd.h to mirror implementation of ZSTD_COMPRESSBOUND
3031
func CompressBound(srcSize int) int {
3132
lowLimit := 128 << 10 // 128 kB
3233
var margin int
3334
if srcSize < lowLimit {
34-
margin = (lowLimit - srcSize) >> 12
35+
margin = (lowLimit - srcSize) >> 11
3536
}
3637
return srcSize + (srcSize >> 8) + margin
3738
}

0 commit comments

Comments
 (0)