lib/storage: inline marshalTags function and remove the code for handling duplicate tags from here

This is a follow-up commit after c8ea697db8
This commit is contained in:
Aliaksandr Valialkin 2021-01-12 15:13:16 +02:00
parent c8ea697db8
commit 31ec79eaf6

View File

@ -375,7 +375,11 @@ func (mn *MetricName) Marshal(dst []byte) []byte {
dst = marshalTagValue(dst, mn.MetricGroup)
// Marshal tags.
dst = marshalTags(dst, mn.Tags)
tags := mn.Tags
for i := range tags {
t := &tags[i]
dst = t.Marshal(dst)
}
return dst
}
@ -635,20 +639,6 @@ func (ts *canonicalTagsSort) Swap(i, j int) {
x[i], x[j] = x[j], x[i]
}
func marshalTags(dst []byte, tags []Tag) []byte {
var prevKey []byte
for i := range tags {
t := &tags[i]
if string(prevKey) == string(t.Key) {
// Skip duplicate keys, since they aren't allowed in Prometheus data model.
continue
}
prevKey = t.Key
dst = t.Marshal(dst)
}
return dst
}
func copyTags(dst, src []Tag) []Tag {
dstLen := len(dst)
if n := dstLen + len(src) - cap(dst); n > 0 {