MCPcopy Index your code
hub / github.com/vmihailenco/msgpack / encodeInternedString

Method encodeInternedString

intern.go:58–73  ·  view source on GitHub ↗
(s string, intern bool)

Source from the content-addressed store, hash-verified

56}
57
58func (e *Encoder) encodeInternedString(s string, intern bool) error {
59 // Interned string takes at least 3 bytes. Plain string 1 byte + string len.
60 if idx, ok := e.dict[s]; ok {
61 return e.encodeInternedStringIndex(idx)
62 }
63
64 if intern && len(s) >= minInternedStringLen && len(e.dict) < maxDictLen {
65 if e.dict == nil {
66 e.dict = make(map[string]int)
67 }
68 idx := len(e.dict)
69 e.dict[s] = idx
70 }
71
72 return e.encodeNormalString(s)
73}
74
75func (e *Encoder) encodeInternedStringIndex(idx int) error {
76 if idx <= math.MaxUint8 {

Callers 3

EncodeStringMethod · 0.95

Calls 2

encodeNormalStringMethod · 0.95

Tested by

no test coverage detected