From: Robert Griesemer Date: Wed, 21 Sep 2011 21:18:48 +0000 (-0700) Subject: gob: slightly simpler code for encodeUint X-Git-Tag: weekly.2011-09-21~7 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=91a48115bb7d773ac38f46e3127b6ca8a6c3e980;p=gostls13.git gob: slightly simpler code for encodeUint R=r CC=golang-dev https://golang.org/cl/5077047 --- diff --git a/src/pkg/gob/encode.go b/src/pkg/gob/encode.go index 317014efda..5100eaad5d 100644 --- a/src/pkg/gob/encode.go +++ b/src/pkg/gob/encode.go @@ -59,15 +59,14 @@ func (state *encoderState) encodeUint(x uint64) { } return } - var n, m int - m = uint64Size - for n = 1; x > 0; n++ { - state.buf[m] = uint8(x) + i := uint64Size + for x > 0 { + state.buf[i] = uint8(x) x >>= 8 - m-- + i-- } - state.buf[m] = uint8(-(n - 1)) - n, err := state.b.Write(state.buf[m : uint64Size+1]) + state.buf[i] = uint8(i - uint64Size) // = loop count, negated + _, err := state.b.Write(state.buf[i : uint64Size+1]) if err != nil { error(err) }