mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Labels: further optimisation for dedupelabels
Inline (by copy-paste) the fast path of `decodeVarint` in various places where it gets called a lot. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
2ced2f6aec
commit
2ba7bc9446
|
@ -113,7 +113,10 @@ func decodeVarint(data string, index int) (int, int) {
|
|||
if b < 0x8000 {
|
||||
return b, index
|
||||
}
|
||||
return decodeVarintRest(b, data, index)
|
||||
}
|
||||
|
||||
func decodeVarintRest(b int, data string, index int) (int, int) {
|
||||
value := int(b & 0x7FFF)
|
||||
b = int(data[index])
|
||||
index++
|
||||
|
@ -128,8 +131,12 @@ func decodeVarint(data string, index int) (int, int) {
|
|||
}
|
||||
|
||||
func decodeString(t *nameTable, data string, index int) (string, int) {
|
||||
var num int
|
||||
num, index = decodeVarint(data, index)
|
||||
// Copy decodeVarint here, because the Go compiler says it's too big to inline.
|
||||
num := int(data[index]) + int(data[index+1])<<8
|
||||
index += 2
|
||||
if num >= 0x8000 {
|
||||
num, index = decodeVarintRest(num, data, index)
|
||||
}
|
||||
return t.ToName(num), index
|
||||
}
|
||||
|
||||
|
@ -323,7 +330,12 @@ func (ls Labels) Get(name string) string {
|
|||
} else if lName[0] > name[0] { // Stop looking if we've gone past.
|
||||
break
|
||||
}
|
||||
_, i = decodeVarint(ls.data, i)
|
||||
// Copy decodeVarint here, because the Go compiler says it's too big to inline.
|
||||
num := int(ls.data[i]) + int(ls.data[i+1])<<8
|
||||
i += 2
|
||||
if num >= 0x8000 {
|
||||
_, i = decodeVarintRest(num, ls.data, i)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -341,7 +353,12 @@ func (ls Labels) Has(name string) bool {
|
|||
} else if lName[0] > name[0] { // Stop looking if we've gone past.
|
||||
break
|
||||
}
|
||||
_, i = decodeVarint(ls.data, i)
|
||||
// Copy decodeVarint here, because the Go compiler says it's too big to inline.
|
||||
num := int(ls.data[i]) + int(ls.data[i+1])<<8
|
||||
i += 2
|
||||
if num >= 0x8000 {
|
||||
_, i = decodeVarintRest(num, ls.data, i)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue