aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/encoding/binary
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-01-18 19:04:36 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-01-18 19:04:36 +0000
commit4f4a855d82a889cebcfca150a7a43909bcb6a346 (patch)
treef12bae0781920fa34669fe30b6f4615a86d9fb80 /libgo/go/encoding/binary
parent225220d668dafb8262db7012bced688acbe63b33 (diff)
downloadgcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.zip
gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.gz
gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.bz2
libgo: update to Go1.12beta2
Reviewed-on: https://go-review.googlesource.com/c/158019 gotools/: * Makefile.am (go_cmd_vet_files): Update for Go1.12beta2 release. (GOTOOLS_TEST_TIMEOUT): Increase to 600. (check-runtime): Export LD_LIBRARY_PATH before computing GOARCH and GOOS. (check-vet): Copy golang.org/x/tools into check-vet-dir. * Makefile.in: Regenerate. gcc/testsuite/: * go.go-torture/execute/names-1.go: Stop using debug/xcoff, which is no longer externally visible. From-SVN: r268084
Diffstat (limited to 'libgo/go/encoding/binary')
-rw-r--r--libgo/go/encoding/binary/binary.go40
1 files changed, 14 insertions, 26 deletions
diff --git a/libgo/go/encoding/binary/binary.go b/libgo/go/encoding/binary/binary.go
index 85b3bc2..8c2d1d9 100644
--- a/libgo/go/encoding/binary/binary.go
+++ b/libgo/go/encoding/binary/binary.go
@@ -161,23 +161,17 @@ func (bigEndian) GoString() string { return "binary.BigEndian" }
func Read(r io.Reader, order ByteOrder, data interface{}) error {
// Fast path for basic types and slices.
if n := intDataSize(data); n != 0 {
- var b [8]byte
- var bs []byte
- if n > len(b) {
- bs = make([]byte, n)
- } else {
- bs = b[:n]
- }
+ bs := make([]byte, n)
if _, err := io.ReadFull(r, bs); err != nil {
return err
}
switch data := data.(type) {
case *bool:
- *data = b[0] != 0
+ *data = bs[0] != 0
case *int8:
- *data = int8(b[0])
+ *data = int8(bs[0])
case *uint8:
- *data = b[0]
+ *data = bs[0]
case *int16:
*data = int16(order.Uint16(bs))
case *uint16:
@@ -260,25 +254,19 @@ func Read(r io.Reader, order ByteOrder, data interface{}) error {
func Write(w io.Writer, order ByteOrder, data interface{}) error {
// Fast path for basic types and slices.
if n := intDataSize(data); n != 0 {
- var b [8]byte
- var bs []byte
- if n > len(b) {
- bs = make([]byte, n)
- } else {
- bs = b[:n]
- }
+ bs := make([]byte, n)
switch v := data.(type) {
case *bool:
if *v {
- b[0] = 1
+ bs[0] = 1
} else {
- b[0] = 0
+ bs[0] = 0
}
case bool:
if v {
- b[0] = 1
+ bs[0] = 1
} else {
- b[0] = 0
+ bs[0] = 0
}
case []bool:
for i, x := range v {
@@ -289,19 +277,19 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error {
}
}
case *int8:
- b[0] = byte(*v)
+ bs[0] = byte(*v)
case int8:
- b[0] = byte(v)
+ bs[0] = byte(v)
case []int8:
for i, x := range v {
bs[i] = byte(x)
}
case *uint8:
- b[0] = *v
+ bs[0] = *v
case uint8:
- b[0] = v
+ bs[0] = v
case []uint8:
- bs = v
+ bs = v // TODO(josharian): avoid allocating bs in this case?
case *int16:
order.PutUint16(bs, uint16(*v))
case int16: