diff options
author | Lynn Boger <laboger@linux.vnet.ibm.com> | 2018-09-10 15:07:09 -0400 |
---|---|---|
committer | Lynn Boger <laboger@linux.vnet.ibm.com> | 2018-09-11 15:14:56 +0000 |
commit | aa4fc0e73654c0a8741d970bfca47c25125633cf (patch) | |
tree | a76a7e03ebdbebb83de72d0862d6c91b9996791b /src/compress | |
parent | 9f2411894ba41d9032623cf637a62846397fec67 (diff) | |
download | go-aa4fc0e73654c0a8741d970bfca47c25125633cf.tar.gz go-aa4fc0e73654c0a8741d970bfca47c25125633cf.zip |
cmd/link,compress/zip,image/png: use binary.{Big,Little}Endian methods
Use the binary.{Big,Little}Endian integer encoding methods rather than
variations found in local implementations. The functions in
the binary package have been tested to ensure they inline correctly and
don't add unnecessary bounds checking.
Change-Id: Ie10111ca6edb7c11e8e5e21c58a5748ae99b7f87
Reviewed-on: https://go-review.googlesource.com/134375
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
Diffstat (limited to 'src/compress')
-rw-r--r-- | src/compress/zlib/writer.go | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/compress/zlib/writer.go b/src/compress/zlib/writer.go index a7b219467e..9986e3834d 100644 --- a/src/compress/zlib/writer.go +++ b/src/compress/zlib/writer.go @@ -6,6 +6,7 @@ package zlib import ( "compress/flate" + "encoding/binary" "fmt" "hash" "hash/adler32" @@ -120,11 +121,7 @@ func (z *Writer) writeHeader() (err error) { } if z.dict != nil { // The next four bytes are the Adler-32 checksum of the dictionary. - checksum := adler32.Checksum(z.dict) - z.scratch[0] = uint8(checksum >> 24) - z.scratch[1] = uint8(checksum >> 16) - z.scratch[2] = uint8(checksum >> 8) - z.scratch[3] = uint8(checksum >> 0) + binary.BigEndian.PutUint32(z.scratch[:], adler32.Checksum(z.dict)) if _, err = z.w.Write(z.scratch[0:4]); err != nil { return err } @@ -190,10 +187,7 @@ func (z *Writer) Close() error { } checksum := z.digest.Sum32() // ZLIB (RFC 1950) is big-endian, unlike GZIP (RFC 1952). - z.scratch[0] = uint8(checksum >> 24) - z.scratch[1] = uint8(checksum >> 16) - z.scratch[2] = uint8(checksum >> 8) - z.scratch[3] = uint8(checksum >> 0) + binary.BigEndian.PutUint32(z.scratch[:], checksum) _, z.err = z.w.Write(z.scratch[0:4]) return z.err } |