mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 19:52:36 +00:00
varints: no need for emit (#24585)
(cherry picked from commit 78835562b1)
This commit is contained in:
@@ -107,15 +107,9 @@ proc writeVu64*(z: var openArray[byte], x: uint64): int =
|
||||
varintWrite32(toOpenArray(z, 5, 8), y)
|
||||
return 9
|
||||
|
||||
proc sar(a, b: int64): int64 {.noinit.} =
|
||||
{.emit: [result, " = ", a, " >> ", b, ";"].}
|
||||
|
||||
proc sal(a, b: int64): int64 {.noinit.} =
|
||||
{.emit: [result, " = ", a, " << ", b, ";"].}
|
||||
|
||||
proc encodeZigzag*(x: int64): uint64 {.inline.} =
|
||||
uint64(sal(x, 1)) xor uint64(sar(x, 63))
|
||||
let xu = uint64(x)
|
||||
(xu shl 1) xor (xu shr 63)
|
||||
|
||||
proc decodeZigzag*(x: uint64): int64 {.inline.} =
|
||||
let casted = cast[int64](x)
|
||||
result = (`shr`(casted, 1)) xor (-(casted and 1))
|
||||
cast[int64]((x shr 1) xor (x shl 63))
|
||||
|
||||
Reference in New Issue
Block a user