Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Use bytes.TrimLeft to strip leading zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
csstaub committed Jul 23, 2015
1 parent feed15e commit 9950c36
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func newBufferFromInt(num uint64) *byteBuffer {
data := make([]byte, 8)
binary.BigEndian.PutUint64(data, num)
return &byteBuffer{
data: trimZeros(data),
data: bytes.TrimLeft(data, "\x00"),
}
}

Expand Down Expand Up @@ -184,15 +184,3 @@ func (b byteBuffer) bigInt() *big.Int {
func (b byteBuffer) toInt() int {
return int(b.bigInt().Int64())
}

func trimZeros(data []byte) []byte {
i := 0
for _, b := range data {
if b == 0 {
i++
} else {
break
}
}
return data[i:]
}

0 comments on commit 9950c36

Please sign in to comment.