MCPcopy Index your code
hub / github.com/cortexproject/cortex / CopyLabels

Function CopyLabels

pkg/cortexpb/compat.go:75–95  ·  view source on GitHub ↗

Efficiently copies labels input slice. To be used in cases where input slice can be reused, but long-term copy is needed.

(input []LabelAdapter)

Source from the content-addressed store, hash-verified

73// Efficiently copies labels input slice. To be used in cases where input slice
74// can be reused, but long-term copy is needed.
75func CopyLabels(input []LabelAdapter) labels.Labels {
76 builder := labels.NewBuilder(labels.EmptyLabels())
77
78 size := 0
79 for _, l := range input {
80 size += len(l.Name)
81 size += len(l.Value)
82 }
83
84 // Copy all strings into the buffer, and use 'yoloString' to convert buffer
85 // slices to strings.
86 buf := make([]byte, size)
87 var name, value string
88
89 for _, l := range input {
90 name, buf = copyStringToBuffer(l.Name, buf)
91 value, buf = copyStringToBuffer(l.Value, buf)
92 builder.Set(name, value)
93 }
94 return builder.Labels()
95}
96
97// Copies string to buffer (which must be big enough), and converts buffer slice containing
98// the string copy into new string.

Callers 1

Calls 3

copyStringToBufferFunction · 0.85
SetMethod · 0.65
LabelsMethod · 0.45

Tested by

no test coverage detected