aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/binary
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/binary')
-rw-r--r--src/encoding/binary/binary.go2
-rw-r--r--src/encoding/binary/binary_test.go27
2 files changed, 26 insertions, 3 deletions
diff --git a/src/encoding/binary/binary.go b/src/encoding/binary/binary.go
index a99ca01994..a31149979d 100644
--- a/src/encoding/binary/binary.go
+++ b/src/encoding/binary/binary.go
@@ -306,7 +306,7 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error {
case uint8:
bs[0] = v
case []uint8:
- bs = v // TODO(josharian): avoid allocating bs in this case?
+ bs = v
case *int16:
order.PutUint16(bs, uint16(*v))
case int16:
diff --git a/src/encoding/binary/binary_test.go b/src/encoding/binary/binary_test.go
index aeb4212ec2..83af89e8a7 100644
--- a/src/encoding/binary/binary_test.go
+++ b/src/encoding/binary/binary_test.go
@@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"io"
- "io/ioutil"
"math"
"reflect"
"strings"
@@ -524,7 +523,7 @@ func BenchmarkWriteStruct(b *testing.B) {
b.SetBytes(int64(Size(&s)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Write(ioutil.Discard, BigEndian, &s)
+ Write(io.Discard, BigEndian, &s)
}
}
@@ -706,3 +705,27 @@ func BenchmarkWriteSlice1000Float32s(b *testing.B) {
}
b.StopTimer()
}
+
+func BenchmarkReadSlice1000Uint8s(b *testing.B) {
+ bsr := &byteSliceReader{}
+ slice := make([]uint8, 1000)
+ buf := make([]byte, len(slice))
+ b.SetBytes(int64(len(buf)))
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ bsr.remain = buf
+ Read(bsr, BigEndian, slice)
+ }
+}
+
+func BenchmarkWriteSlice1000Uint8s(b *testing.B) {
+ slice := make([]uint8, 1000)
+ buf := new(bytes.Buffer)
+ var w io.Writer = buf
+ b.SetBytes(1000)
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ buf.Reset()
+ Write(w, BigEndian, slice)
+ }
+}