String will look like `{foo="bar", more="less"}`. Names are sorted alphabetically.
()
| 21 | |
| 22 | // String will look like `{foo="bar", more="less"}`. Names are sorted alphabetically. |
| 23 | func (l LabelSet) String() string { |
| 24 | var lna [32]string // On stack to avoid memory allocation for sorting names. |
| 25 | labelNames := lna[:0] |
| 26 | for name := range l { |
| 27 | labelNames = append(labelNames, string(name)) |
| 28 | } |
| 29 | slices.Sort(labelNames) |
| 30 | var bytea [1024]byte // On stack to avoid memory allocation while building the output. |
| 31 | b := bytes.NewBuffer(bytea[:0]) |
| 32 | b.WriteByte('{') |
| 33 | for i, name := range labelNames { |
| 34 | if i > 0 { |
| 35 | b.WriteString(", ") |
| 36 | } |
| 37 | b.WriteString(name) |
| 38 | b.WriteByte('=') |
| 39 | b.Write(strconv.AppendQuote(b.AvailableBuffer(), string(l[LabelName(name)]))) |
| 40 | } |
| 41 | b.WriteByte('}') |
| 42 | return b.String() |
| 43 | } |
nothing calls this directly
no test coverage detected