aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLorenz Bauer <oss@lmb.io>2024-04-16 09:15:41 +0100
committerGopher Robot <gobot@golang.org>2024-05-13 21:22:39 +0000
commitec1724bc99fe0532d36aa190240e1d802937851e (patch)
tree268700eb39a51bb59cac0e9352d99774de7da076 /src
parent59003b6d8795f337c8916e814343182116183491 (diff)
downloadgo-ec1724bc99fe0532d36aa190240e1d802937851e.tar.gz
go-ec1724bc99fe0532d36aa190240e1d802937851e.zip
encoding/binary: simplify encoder.value
Remove some duplicate type switching from encoder.value. reflect.Uint and reflect.Int don't have a case statement anymore, but since they aren't valid types there is no change in semantics. goos: darwin goarch: arm64 pkg: encoding/binary cpu: Apple M1 Pro │ base.txt │ simplify.txt │ │ sec/op │ sec/op vs base │ ReadSlice1000Int32s-10 2.649µ ± 1% 2.645µ ± 0% ~ (p=0.069 n=6) ReadStruct-10 204.8n ± 2% 199.9n ± 0% -2.39% (p=0.002 n=6) WriteStruct-10 185.6n ± 2% 154.0n ± 0% -17.03% (p=0.002 n=6) WriteSlice1000Structs-10 157.9µ ± 1% 125.0µ ± 0% -20.86% (p=0.002 n=6) ReadSlice1000Structs-10 162.6µ ± 2% 159.3µ ± 0% ~ (p=0.065 n=6) ReadInts-10 159.7n ± 1% 156.7n ± 0% -1.88% (p=0.002 n=6) WriteInts-10 134.2n ± 0% 134.1n ± 0% -0.11% (p=0.011 n=6) WriteSlice1000Int32s-10 2.680µ ± 0% 2.680µ ± 0% ~ (p=0.955 n=6) PutUint16-10 0.6253n ± 2% 0.6211n ± 0% -0.67% (p=0.013 n=6) AppendUint16-10 1.417n ± 2% 1.413n ± 0% ~ (p=0.065 n=6) PutUint32-10 0.6210n ± 0% 0.6210n ± 0% ~ (p=0.835 n=6) AppendUint32-10 1.414n ± 0% 1.414n ± 0% ~ (p=1.000 n=6) PutUint64-10 0.6210n ± 0% 0.6212n ± 0% ~ (p=0.260 n=6) AppendUint64-10 1.414n ± 1% 1.417n ± 0% ~ (p=0.097 n=6) LittleEndianPutUint16-10 0.6236n ± 0% 0.6238n ± 0% ~ (p=0.426 n=6) LittleEndianAppendUint16-10 1.419n ± 0% 1.421n ± 1% ~ (p=0.054 n=6) LittleEndianPutUint32-10 0.6236n ± 0% 0.6239n ± 0% ~ (p=0.457 n=6) LittleEndianAppendUint32-10 1.421n ± 3% 1.421n ± 0% ~ (p=1.000 n=6) LittleEndianPutUint64-10 0.6242n ± 1% 0.6239n ± 0% ~ (p=0.372 n=6) LittleEndianAppendUint64-10 1.421n ± 0% 1.421n ± 0% ~ (p=1.000 n=6) ReadFloats-10 39.39n ± 0% 39.35n ± 0% -0.10% (p=0.026 n=6) WriteFloats-10 33.64n ± 0% 33.65n ± 0% ~ (p=0.297 n=6) ReadSlice1000Float32s-10 2.661µ ± 0% 2.664µ ± 0% ~ (p=0.916 n=6) WriteSlice1000Float32s-10 2.763µ ± 0% 2.758µ ± 2% ~ (p=0.225 n=6) ReadSlice1000Uint8s-10 129.5n ± 2% 129.5n ± 2% ~ (p=0.485 n=6) WriteSlice1000Uint8s-10 144.4n ± 4% 146.1n ± 2% ~ (p=0.065 n=6) PutUvarint32-10 12.12n ± 0% 12.12n ± 2% ~ (p=0.933 n=6) PutUvarint64-10 30.75n ± 0% 31.29n ± 1% +1.76% (p=0.002 n=6) geomean 33.44n 32.89n -1.65% Change-Id: Ibce978012c268a7f26fe7567c340c861fa4b115d Reviewed-on: https://go-review.googlesource.com/c/go/+/579156 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
-rw-r--r--src/encoding/binary/binary.go68
1 files changed, 28 insertions, 40 deletions
diff --git a/src/encoding/binary/binary.go b/src/encoding/binary/binary.go
index 634995a5bd..291e494dd4 100644
--- a/src/encoding/binary/binary.go
+++ b/src/encoding/binary/binary.go
@@ -722,49 +722,37 @@ func (e *encoder) value(v reflect.Value) {
case reflect.Bool:
e.bool(v.Bool())
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- switch v.Type().Kind() {
- case reflect.Int8:
- e.int8(int8(v.Int()))
- case reflect.Int16:
- e.int16(int16(v.Int()))
- case reflect.Int32:
- e.int32(int32(v.Int()))
- case reflect.Int64:
- e.int64(v.Int())
- }
+ case reflect.Int8:
+ e.int8(int8(v.Int()))
+ case reflect.Int16:
+ e.int16(int16(v.Int()))
+ case reflect.Int32:
+ e.int32(int32(v.Int()))
+ case reflect.Int64:
+ e.int64(v.Int())
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- switch v.Type().Kind() {
- case reflect.Uint8:
- e.uint8(uint8(v.Uint()))
- case reflect.Uint16:
- e.uint16(uint16(v.Uint()))
- case reflect.Uint32:
- e.uint32(uint32(v.Uint()))
- case reflect.Uint64:
- e.uint64(v.Uint())
- }
+ case reflect.Uint8:
+ e.uint8(uint8(v.Uint()))
+ case reflect.Uint16:
+ e.uint16(uint16(v.Uint()))
+ case reflect.Uint32:
+ e.uint32(uint32(v.Uint()))
+ case reflect.Uint64:
+ e.uint64(v.Uint())
- case reflect.Float32, reflect.Float64:
- switch v.Type().Kind() {
- case reflect.Float32:
- e.uint32(math.Float32bits(float32(v.Float())))
- case reflect.Float64:
- e.uint64(math.Float64bits(v.Float()))
- }
+ case reflect.Float32:
+ e.uint32(math.Float32bits(float32(v.Float())))
+ case reflect.Float64:
+ e.uint64(math.Float64bits(v.Float()))
- case reflect.Complex64, reflect.Complex128:
- switch v.Type().Kind() {
- case reflect.Complex64:
- x := v.Complex()
- e.uint32(math.Float32bits(float32(real(x))))
- e.uint32(math.Float32bits(float32(imag(x))))
- case reflect.Complex128:
- x := v.Complex()
- e.uint64(math.Float64bits(real(x)))
- e.uint64(math.Float64bits(imag(x)))
- }
+ case reflect.Complex64:
+ x := v.Complex()
+ e.uint32(math.Float32bits(float32(real(x))))
+ e.uint32(math.Float32bits(float32(imag(x))))
+ case reflect.Complex128:
+ x := v.Complex()
+ e.uint64(math.Float64bits(real(x)))
+ e.uint64(math.Float64bits(imag(x)))
}
}