MCPcopy Create free account
hub / github.com/prometheus/common / String

Method String

model/labelset_string.go:23–43  ·  view source on GitHub ↗

String will look like `{foo="bar", more="less"}`. Names are sorted alphabetically.

()

Source from the content-addressed store, hash-verified

21
22// String will look like `{foo="bar", more="less"}`. Names are sorted alphabetically.
23func (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}

Callers

nothing calls this directly

Calls 4

LabelNameTypeAlias · 0.85
WriteByteMethod · 0.80
WriteStringMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected