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

Function emitLiteral

s2/encode_go.go:80–114  ·  view source on GitHub ↗

emitLiteral writes a literal chunk and returns the number of bytes written. It assumes that: dst is long enough to hold the encoded bytes 0 <= len(lit) && len(lit) <= math.MaxUint32

(dst, lit []byte)

Source from the content-addressed store, hash-verified

78// dst is long enough to hold the encoded bytes
79// 0 <= len(lit) && len(lit) <= math.MaxUint32
80func emitLiteral(dst, lit []byte) int {
81 if len(lit) == 0 {
82 return 0
83 }
84 const num = 63<<2 | tagLiteral
85 i, n := 0, uint(len(lit)-1)
86 switch {
87 case n < 60:
88 dst[0] = uint8(n)<<2 | tagLiteral
89 i = 1
90 case n < 1<<8:
91 dst[1] = uint8(n)
92 dst[0] = 60<<2 | tagLiteral
93 i = 2
94 case n < 1<<16:
95 dst[2] = uint8(n >> 8)
96 dst[1] = uint8(n)
97 dst[0] = 61<<2 | tagLiteral
98 i = 3
99 case n < 1<<24:
100 dst[3] = uint8(n >> 16)
101 dst[2] = uint8(n >> 8)
102 dst[1] = uint8(n)
103 dst[0] = 62<<2 | tagLiteral
104 i = 4
105 default:
106 dst[4] = uint8(n >> 24)
107 dst[3] = uint8(n >> 16)
108 dst[2] = uint8(n >> 8)
109 dst[1] = uint8(n)
110 dst[0] = 63<<2 | tagLiteral
111 i = 5
112 }
113 return i + copy(dst[i:], lit)
114}
115
116// emitRepeat writes a repeat chunk and returns the number of bytes written.
117// Length must be at least 4 and < 1<<24

Callers 15

encodeBlockBetterGoFunction · 0.70
encodeBlockBetterGo64KFunction · 0.70
encodeBlockBetterDictFunction · 0.70
encodeGoFunction · 0.70
encodeBlockGoFunction · 0.70
encodeBlockGo64KFunction · 0.70
encodeBlockSnappyGoFunction · 0.70
encodeBlockSnappyGo64KFunction · 0.70
encodeBlockDictGoFunction · 0.70
TestEmitLiteralFunction · 0.70

Calls

no outgoing calls

Tested by 1

TestEmitLiteralFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…