Skip to content

Commit

Permalink
faster VarintSize() (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyyangz authored and tac0turtle committed Oct 10, 2019
1 parent c666557 commit 3d0675e
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

//----------------------------------------
Expand Down

0 comments on commit 3d0675e

Please sign in to comment.