mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
wip
This commit is contained in:
parent
6d3b506dcf
commit
d724da794f
2 changed files with 31 additions and 7 deletions
|
@ -83,9 +83,22 @@ func UnmarshalInt64(src []byte) int64 {
|
|||
|
||||
// MarshalVarInt64 appends marshalsed v to dst and returns the result.
|
||||
func MarshalVarInt64(dst []byte, v int64) []byte {
|
||||
var tmp [1]int64
|
||||
tmp[0] = v
|
||||
return MarshalVarInt64s(dst, tmp[:])
|
||||
u := uint64((v << 1) ^ (v >> 63))
|
||||
|
||||
if v < (1<<6) && v > (-1<<6) {
|
||||
return append(dst, byte(u))
|
||||
}
|
||||
if u < (1 << (2 * 7)) {
|
||||
return append(dst, byte(u|0x80), byte(u>>7))
|
||||
}
|
||||
if u < (1 << (3 * 7)) {
|
||||
return append(dst, byte(u|0x80), byte((u>>7)|0x80), byte(u>>(2*7)))
|
||||
}
|
||||
|
||||
// Slow path for big integers
|
||||
var tmp [1]uint64
|
||||
tmp[0] = u
|
||||
return MarshalVarUint64s(dst, tmp[:])
|
||||
}
|
||||
|
||||
// MarshalVarInt64s appends marshaled vs to dst and returns the result.
|
||||
|
@ -268,6 +281,17 @@ func unmarshalVarInt64sSlow(dst []int64, src []byte) ([]byte, error) {
|
|||
|
||||
// MarshalVarUint64 appends marshaled u to dst and returns the result.
|
||||
func MarshalVarUint64(dst []byte, u uint64) []byte {
|
||||
if u < (1 << 7) {
|
||||
return append(dst, byte(u))
|
||||
}
|
||||
if u < (1 << (2 * 7)) {
|
||||
return append(dst, byte(u|0x80), byte(u>>7))
|
||||
}
|
||||
if u < (1 << (3 * 7)) {
|
||||
return append(dst, byte(u|0x80), byte((u>>7)|0x80), byte(u>>(2*7)))
|
||||
}
|
||||
|
||||
// Slow path for big integers.
|
||||
var tmp [1]uint64
|
||||
tmp[0] = u
|
||||
return MarshalVarUint64s(dst, tmp[:])
|
||||
|
|
|
@ -233,10 +233,10 @@ func benchmarkUnmarshalVarInt64s(b *testing.B, maxValue int64) {
|
|||
|
||||
func BenchmarkMarshalVarUint64(b *testing.B) {
|
||||
b.Run("small-ints", func(b *testing.B) {
|
||||
benchmarkMarshalVarUint64(b, []uint64{1,2,3,4,5,67,127})
|
||||
benchmarkMarshalVarUint64(b, []uint64{1, 2, 3, 4, 5, 67, 127})
|
||||
})
|
||||
b.Run("big-ints", func(b *testing.B) {
|
||||
benchmarkMarshalVarUint64(b, []uint64{12355,89832432, 8989843, 8989989, 883443, 9891233, 8232434342})
|
||||
benchmarkMarshalVarUint64(b, []uint64{12355, 89832432, 8989843, 8989989, 883443, 9891233, 8232434342})
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -259,10 +259,10 @@ func benchmarkMarshalVarUint64(b *testing.B, a []uint64) {
|
|||
|
||||
func BenchmarkMarshalVarInt64(b *testing.B) {
|
||||
b.Run("small-ints", func(b *testing.B) {
|
||||
benchmarkMarshalVarInt64(b, []int64{1,2,3,-4,5,-60,63})
|
||||
benchmarkMarshalVarInt64(b, []int64{1, 2, 3, -4, 5, -60, 63})
|
||||
})
|
||||
b.Run("big-ints", func(b *testing.B) {
|
||||
benchmarkMarshalVarInt64(b, []int64{12355,-89832432, 8989843, -8989989, 883443, -9891233, 8232434342})
|
||||
benchmarkMarshalVarInt64(b, []int64{12355, -89832432, 8989843, -8989989, 883443, -9891233, 8232434342})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue