From fbf776258498dbb3aa6637ca82c7fe5c7255fd2f Mon Sep 17 00:00:00 2001 From: rickyyangz <38900912+rickyyangz@users.noreply.github.com> Date: Thu, 10 Oct 2019 21:39:04 +0800 Subject: [PATCH] faster VarintSize() (#282) --- encoder.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/encoder.go b/encoder.go index ba786e73..9130ddec 100644 --- a/encoder.go +++ b/encoder.go @@ -42,9 +42,7 @@ func EncodeVarint(w io.Writer, i int64) (err error) { } func VarintSize(i int64) int { - var buf [10]byte - n := binary.PutVarint(buf[:], i) - return n + return UvarintSize(uint64((uint64(i) << 1) ^ uint64(i>>63))) } //----------------------------------------