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

Function EncodeSnappyBetter

s2/encode.go:248–276  ·  view source on GitHub ↗

EncodeSnappyBetter 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. The output is Snappy compatible and will likely decompress faster. The dst and src must n

(dst, src []byte)

Source from the content-addressed store, hash-verified

246// If you need to encode larger amounts of data, consider using
247// the streaming interface which gives all of these features.
248func EncodeSnappyBetter(dst, src []byte) []byte {
249 if n := MaxEncodedLen(len(src)); n < 0 {
250 panic(ErrTooLarge)
251 } else if cap(dst) < n {
252 dst = make([]byte, n)
253 } else {
254 dst = dst[:n]
255 }
256
257 // The block starts with the varint-encoded length of the decompressed bytes.
258 d := binary.PutUvarint(dst, uint64(len(src)))
259
260 if len(src) == 0 {
261 return dst[:d]
262 }
263 if len(src) < minNonLiteralBlockSize {
264 d += emitLiteral(dst[d:], src)
265 return dst[:d]
266 }
267
268 n := encodeBlockBetterSnappy(dst[d:], src)
269 if n > 0 {
270 d += n
271 return dst[:d]
272 }
273 // Not compressible
274 d += emitLiteral(dst[d:], src)
275 return dst[:d]
276}
277
278// EncodeSnappyBest returns the encoded form of src. The returned slice may be a sub-
279// slice of dst if dst was large enough to hold the entire encoded block.

Callers 7

EncodeFunction · 0.92
EncodeBetterFunction · 0.92
mainFunction · 0.92
FuzzEncodingBlocksFunction · 0.85
testSnappyBlockRoundtripFunction · 0.85
benchEncodeFunction · 0.85
benchFileSnappyFunction · 0.85

Calls 3

MaxEncodedLenFunction · 0.70
emitLiteralFunction · 0.70
encodeBlockBetterSnappyFunction · 0.70

Tested by 4

FuzzEncodingBlocksFunction · 0.68
testSnappyBlockRoundtripFunction · 0.68
benchEncodeFunction · 0.68
benchFileSnappyFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…