mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Labels.Has quick check on first character
Exit early if we've gone past - labels are sorted in order. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
33aab1b2cc
commit
b5c6807fea
|
@ -300,13 +300,26 @@ func (ls Labels) Get(name string) string {
|
||||||
|
|
||||||
// Has returns true if the label with the given name is present.
|
// Has returns true if the label with the given name is present.
|
||||||
func (ls Labels) Has(name string) bool {
|
func (ls Labels) Has(name string) bool {
|
||||||
|
if name == "" { // Avoid crash in loop if someone asks for "".
|
||||||
|
return false // Prometheus does not store blank label names.
|
||||||
|
}
|
||||||
for i := 0; i < len(ls.data); {
|
for i := 0; i < len(ls.data); {
|
||||||
var lName string
|
var size int
|
||||||
lName, i = decodeString(ls.data, i)
|
size, i = decodeSize(ls.data, i)
|
||||||
_, i = decodeString(ls.data, i)
|
if ls.data[i] == name[0] {
|
||||||
if lName == name {
|
lName := ls.data[i : i+size]
|
||||||
return true
|
i += size
|
||||||
|
if lName == name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ls.data[i] > name[0] { // Stop looking if we've gone past.
|
||||||
|
break
|
||||||
|
}
|
||||||
|
i += size
|
||||||
}
|
}
|
||||||
|
size, i = decodeSize(ls.data, i)
|
||||||
|
i += size
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue