MCPcopy Index your code
hub / github.com/klauspost/compress / EncodeBetter

Function EncodeBetter

s2/encode.go:117–144  ·  view source on GitHub ↗

EncodeBetter 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. EncodeBetter compresses better than Encode but typically with a 10-40% speed decrease on both co

(dst, src []byte)

Source from the content-addressed store, hash-verified

115// If you need to encode larger amounts of data, consider using
116// the streaming interface which gives all of these features.
117func EncodeBetter(dst, src []byte) []byte {
118 if n := MaxEncodedLen(len(src)); n < 0 {
119 panic(ErrTooLarge)
120 } else if cap(dst) < n {
121 dst = make([]byte, n)
122 } else {
123 dst = dst[:n]
124 }
125
126 // The block starts with the varint-encoded length of the decompressed bytes.
127 d := binary.PutUvarint(dst, uint64(len(src)))
128
129 if len(src) == 0 {
130 return dst[:d]
131 }
132 if len(src) < minNonLiteralBlockSize {
133 d += emitLiteral(dst[d:], src)
134 return dst[:d]
135 }
136 n := encodeBlockBetter(dst[d:], src)
137 if n > 0 {
138 d += n
139 return dst[:d]
140 }
141 // Not compressible
142 d += emitLiteral(dst[d:], src)
143 return dst[:d]
144}
145
146// EncodeBest returns the encoded form of src. The returned slice may be a sub-
147// slice of dst if dst was large enough to hold the entire encoded block.

Callers 14

mainFunction · 0.92
TestEncodeHugeFunction · 0.70
FuzzEncodingBlocksFunction · 0.70
FuzzDecodeBlockFunction · 0.70
roundtripFunction · 0.70
testBetterBlockRoundtripFunction · 0.70
benchDecodeFunction · 0.70
benchEncodeFunction · 0.70
benchFileFunction · 0.70
TestEncoderRegressionFunction · 0.70

Calls 3

MaxEncodedLenFunction · 0.70
emitLiteralFunction · 0.70
encodeBlockBetterFunction · 0.70

Tested by 13

TestEncodeHugeFunction · 0.56
FuzzEncodingBlocksFunction · 0.56
FuzzDecodeBlockFunction · 0.56
roundtripFunction · 0.56
testBetterBlockRoundtripFunction · 0.56
benchDecodeFunction · 0.56
benchEncodeFunction · 0.56
benchFileFunction · 0.56
TestEncoderRegressionFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…