(s string, intern bool)
| 56 | } |
| 57 | |
| 58 | func (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 | |
| 75 | func (e *Encoder) encodeInternedStringIndex(idx int) error { |
| 76 | if idx <= math.MaxUint8 { |
no test coverage detected