]> Cypherpunks repositories - gostls13.git/commitdiff
gob: slightly simpler code for encodeUint
authorRobert Griesemer <gri@golang.org>
Wed, 21 Sep 2011 21:18:48 +0000 (14:18 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 21 Sep 2011 21:18:48 +0000 (14:18 -0700)
R=r
CC=golang-dev
https://golang.org/cl/5077047

src/pkg/gob/encode.go

index 317014efdad91048f1b6186d07161f6cd0b67b96..5100eaad5d18743926836f319167e4a8bc0ab11d 100644 (file)
@@ -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)
        }