mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-13 04:52:19 +02:00
negentropy: slightly faster encodeVarInt()
This commit is contained in:
@ -125,15 +125,19 @@ func encodeVarInt(n int) []byte {
|
|||||||
return []byte{0}
|
return []byte{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
var o []byte
|
result := make([]byte, 8)
|
||||||
|
idx := 7
|
||||||
|
|
||||||
for n != 0 {
|
for n != 0 {
|
||||||
o = append([]byte{byte(n & 0x7F)}, o...)
|
result[idx] = byte(n & 0x7F)
|
||||||
n >>= 7
|
n >>= 7
|
||||||
|
idx--
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(o)-1; i++ {
|
result = result[idx+1:]
|
||||||
o[i] |= 0x80
|
for i := 0; i < len(result)-1; i++ {
|
||||||
|
result[i] |= 0x80
|
||||||
}
|
}
|
||||||
|
|
||||||
return o
|
return result
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user