mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
model/labels (dedupelabels): small clarifications
Suggestion from @colega. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
c8c28efcb3
commit
d16ce3c9bd
|
@ -81,10 +81,10 @@ func (t *SymbolTable) toNumUnlocked(name string) int {
|
||||||
}
|
}
|
||||||
i := t.nextNum
|
i := t.nextNum
|
||||||
if t.nextNum == cap(t.byNum) {
|
if t.nextNum == cap(t.byNum) {
|
||||||
// Name table is full; copy to a new one. Don't touch the existing slice.
|
// Name table is full; copy to a new one. Don't touch the existing slice, as nameTable is immutable after construction.
|
||||||
oldSlice := t.byNum
|
newSlice := make([]string, cap(t.byNum)*2)
|
||||||
t.nameTable = &nameTable{byNum: make([]string, cap(oldSlice)*2), symbolTable: t}
|
copy(newSlice, t.byNum)
|
||||||
copy(t.nameTable.byNum, oldSlice)
|
t.nameTable = &nameTable{byNum: newSlice, symbolTable: t}
|
||||||
}
|
}
|
||||||
name = strings.Clone(name)
|
name = strings.Clone(name)
|
||||||
t.byNum[i] = name
|
t.byNum[i] = name
|
||||||
|
@ -112,18 +112,18 @@ func decodeVarint(data string, index int) (int, int) {
|
||||||
if b < 0x80 {
|
if b < 0x80 {
|
||||||
return int(b), index
|
return int(b), index
|
||||||
}
|
}
|
||||||
size := int(b & 0x7F)
|
value := int(b & 0x7F)
|
||||||
for shift := uint(7); ; shift += 7 {
|
for shift := uint(7); ; shift += 7 {
|
||||||
// Just panic if we go of the end of data, since all Labels strings are constructed internally and
|
// Just panic if we go of the end of data, since all Labels strings are constructed internally and
|
||||||
// malformed data indicates a bug, or memory corruption.
|
// malformed data indicates a bug, or memory corruption.
|
||||||
b := data[index]
|
b := data[index]
|
||||||
index++
|
index++
|
||||||
size |= int(b&0x7F) << shift
|
value |= int(b&0x7F) << shift
|
||||||
if b < 0x80 {
|
if b < 0x80 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return size, index
|
return value, index
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeString(t *nameTable, data string, index int) (string, int) {
|
func decodeString(t *nameTable, data string, index int) (string, int) {
|
||||||
|
@ -304,8 +304,7 @@ func (ls Labels) BytesWithoutLabels(buf []byte, names ...string) []byte {
|
||||||
|
|
||||||
// Copy returns a copy of the labels.
|
// Copy returns a copy of the labels.
|
||||||
func (ls Labels) Copy() Labels {
|
func (ls Labels) Copy() Labels {
|
||||||
buf := append([]byte{}, ls.data...)
|
return Labels{syms: ls.syms, data: strings.Clone(ls.data)}
|
||||||
return Labels{syms: ls.syms, data: yoloString(buf)}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the value for the label with the given name.
|
// Get returns the value for the label with the given name.
|
||||||
|
|
Loading…
Reference in a new issue