MCPcopy
hub / github.com/klauspost/compress / EncodeBest

Function EncodeBest

s2/encode.go:161–188  ·  view source on GitHub ↗

EncodeBest returns the encoded form of src. The returned slice may be a sub- slice of dst if dst was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. EncodeBest compresses as good as reasonably possible but with a big speed decrease. The dst and s

(dst, src []byte)

Source from the content-addressed store, hash-verified

159// If you need to encode larger amounts of data, consider using
160// the streaming interface which gives all of these features.
161func EncodeBest(dst, src []byte) []byte {
162 if n := MaxEncodedLen(len(src)); n < 0 {
163 panic(ErrTooLarge)
164 } else if cap(dst) < n {
165 dst = make([]byte, n)
166 } else {
167 dst = dst[:n]
168 }
169
170 // The block starts with the varint-encoded length of the decompressed bytes.
171 d := binary.PutUvarint(dst, uint64(len(src)))
172
173 if len(src) == 0 {
174 return dst[:d]
175 }
176 if len(src) < minNonLiteralBlockSize {
177 d += emitLiteral(dst[d:], src)
178 return dst[:d]
179 }
180 n := encodeBlockBest(dst[d:], src, nil)
181 if n > 0 {
182 d += n
183 return dst[:d]
184 }
185 // Not compressible
186 d += emitLiteral(dst[d:], src)
187 return dst[:d]
188}
189
190// EncodeSnappy returns the encoded form of src. The returned slice may be a sub-
191// slice of dst if dst was large enough to hold the entire encoded block.

Callers 8

mainFunction · 0.92
TestEncodeHugeFunction · 0.85
FuzzEncodingBlocksFunction · 0.85
testBestBlockRoundtripFunction · 0.85
benchDecodeFunction · 0.85
benchEncodeFunction · 0.85
benchFileFunction · 0.85
TestEncoderRegressionFunction · 0.85

Calls 3

encodeBlockBestFunction · 0.85
MaxEncodedLenFunction · 0.70
emitLiteralFunction · 0.70

Tested by 7

TestEncodeHugeFunction · 0.68
FuzzEncodingBlocksFunction · 0.68
testBestBlockRoundtripFunction · 0.68
benchDecodeFunction · 0.68
benchEncodeFunction · 0.68
benchFileFunction · 0.68
TestEncoderRegressionFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…