Skip to content

Commit

Permalink
Labels: small optimisation of decodeString for dedupelabels
Browse files Browse the repository at this point in the history
Signed-off-by: Bryan Boreham <[email protected]>
  • Loading branch information
bboreham committed Jun 5, 2024
1 parent 1b0c990 commit 579c6a0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions model/labels/labels_dedupelabels.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,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++
Expand All @@ -129,8 +132,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
}

Expand Down

0 comments on commit 579c6a0

Please sign in to comment.