encoding/gob: simplify allocation in decode.
The old code's structure needed to track indirections because of the
use of unsafe. That is no longer necessary, so we can remove all
that tracking. The code cleans up considerably but is a little slower.
We may be able to recover that performance drop. I believe the
code quality improvement is worthwhile regardless.
BenchmarkEndToEndPipe 5610 5780 +3.03%
BenchmarkEndToEndByteBuffer 3156 3222 +2.09%
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/103700043
diff --git a/src/pkg/encoding/gob/codec_test.go b/src/pkg/encoding/gob/codec_test.go
index a6012f5..c7b2567 100644
--- a/src/pkg/encoding/gob/codec_test.go
+++ b/src/pkg/encoding/gob/codec_test.go
@@ -323,7 +323,7 @@
if v+state.fieldnum != 6 {
t.Fatalf("decoding field number %d, got %d", 6, v+state.fieldnum)
}
- instr.op(instr, state, decIndirect(value, instr.indir))
+ instr.op(instr, state, value)
state.fieldnum = 6
}
@@ -342,7 +342,7 @@
// bool
{
var data bool
- instr := &decInstr{decBool, 6, nil, 1, ovfl}
+ instr := &decInstr{decBool, 6, nil, ovfl}
state := newDecodeStateFromData(boolResult)
execDec("bool", instr, state, t, reflect.ValueOf(&data))
if data != true {
@@ -352,7 +352,7 @@
// int
{
var data int
- instr := &decInstr{decOpTable[reflect.Int], 6, nil, 1, ovfl}
+ instr := &decInstr{decOpTable[reflect.Int], 6, nil, ovfl}
state := newDecodeStateFromData(signedResult)
execDec("int", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -363,7 +363,7 @@
// uint
{
var data uint
- instr := &decInstr{decOpTable[reflect.Uint], 6, nil, 1, ovfl}
+ instr := &decInstr{decOpTable[reflect.Uint], 6, nil, ovfl}
state := newDecodeStateFromData(unsignedResult)
execDec("uint", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -374,7 +374,7 @@
// int8
{
var data int8
- instr := &decInstr{decInt8, 6, nil, 1, ovfl}
+ instr := &decInstr{decInt8, 6, nil, ovfl}
state := newDecodeStateFromData(signedResult)
execDec("int8", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -385,7 +385,7 @@
// uint8
{
var data uint8
- instr := &decInstr{decUint8, 6, nil, 1, ovfl}
+ instr := &decInstr{decUint8, 6, nil, ovfl}
state := newDecodeStateFromData(unsignedResult)
execDec("uint8", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -396,7 +396,7 @@
// int16
{
var data int16
- instr := &decInstr{decInt16, 6, nil, 1, ovfl}
+ instr := &decInstr{decInt16, 6, nil, ovfl}
state := newDecodeStateFromData(signedResult)
execDec("int16", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -407,7 +407,7 @@
// uint16
{
var data uint16
- instr := &decInstr{decUint16, 6, nil, 1, ovfl}
+ instr := &decInstr{decUint16, 6, nil, ovfl}
state := newDecodeStateFromData(unsignedResult)
execDec("uint16", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -418,7 +418,7 @@
// int32
{
var data int32
- instr := &decInstr{decInt32, 6, nil, 1, ovfl}
+ instr := &decInstr{decInt32, 6, nil, ovfl}
state := newDecodeStateFromData(signedResult)
execDec("int32", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -429,7 +429,7 @@
// uint32
{
var data uint32
- instr := &decInstr{decUint32, 6, nil, 1, ovfl}
+ instr := &decInstr{decUint32, 6, nil, ovfl}
state := newDecodeStateFromData(unsignedResult)
execDec("uint32", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -440,7 +440,7 @@
// uintptr
{
var data uintptr
- instr := &decInstr{decOpTable[reflect.Uintptr], 6, nil, 1, ovfl}
+ instr := &decInstr{decOpTable[reflect.Uintptr], 6, nil, ovfl}
state := newDecodeStateFromData(unsignedResult)
execDec("uintptr", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -451,7 +451,7 @@
// int64
{
var data int64
- instr := &decInstr{decInt64, 6, nil, 1, ovfl}
+ instr := &decInstr{decInt64, 6, nil, ovfl}
state := newDecodeStateFromData(signedResult)
execDec("int64", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -462,7 +462,7 @@
// uint64
{
var data uint64
- instr := &decInstr{decUint64, 6, nil, 1, ovfl}
+ instr := &decInstr{decUint64, 6, nil, ovfl}
state := newDecodeStateFromData(unsignedResult)
execDec("uint64", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -473,7 +473,7 @@
// float32
{
var data float32
- instr := &decInstr{decFloat32, 6, nil, 1, ovfl}
+ instr := &decInstr{decFloat32, 6, nil, ovfl}
state := newDecodeStateFromData(floatResult)
execDec("float32", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -484,7 +484,7 @@
// float64
{
var data float64
- instr := &decInstr{decFloat64, 6, nil, 1, ovfl}
+ instr := &decInstr{decFloat64, 6, nil, ovfl}
state := newDecodeStateFromData(floatResult)
execDec("float64", instr, state, t, reflect.ValueOf(&data))
if data != 17 {
@@ -495,7 +495,7 @@
// complex64
{
var data complex64
- instr := &decInstr{decOpTable[reflect.Complex64], 6, nil, 1, ovfl}
+ instr := &decInstr{decOpTable[reflect.Complex64], 6, nil, ovfl}
state := newDecodeStateFromData(complexResult)
execDec("complex", instr, state, t, reflect.ValueOf(&data))
if data != 17+19i {
@@ -506,7 +506,7 @@
// complex128
{
var data complex128
- instr := &decInstr{decOpTable[reflect.Complex128], 6, nil, 1, ovfl}
+ instr := &decInstr{decOpTable[reflect.Complex128], 6, nil, ovfl}
state := newDecodeStateFromData(complexResult)
execDec("complex", instr, state, t, reflect.ValueOf(&data))
if data != 17+19i {
@@ -517,7 +517,7 @@
// bytes == []uint8
{
var data []byte
- instr := &decInstr{decUint8Slice, 6, nil, 1, ovfl}
+ instr := &decInstr{decUint8Slice, 6, nil, ovfl}
state := newDecodeStateFromData(bytesResult)
execDec("bytes", instr, state, t, reflect.ValueOf(&data))
if string(data) != "hello" {
@@ -528,7 +528,7 @@
// string
{
var data string
- instr := &decInstr{decString, 6, nil, 1, ovfl}
+ instr := &decInstr{decString, 6, nil, ovfl}
state := newDecodeStateFromData(bytesResult)
execDec("bytes", instr, state, t, reflect.ValueOf(&data))
if data != "hello" {