diff options
author | Rob Pike <r@golang.org> | 2009-10-11 18:07:47 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-10-11 18:07:47 -0700 |
commit | cfe7513777f044621537e2b823e4ea243945ca18 (patch) | |
tree | 7c858514a32cc598b79ff980e09256fd0f79b8aa | |
parent | 92b93dd042130a68d3784c690b74b6db75d7c770 (diff) | |
download | golang-cfe7513777f044621537e2b823e4ea243945ca18.tar.gz |
better code for allocation through indirection
R=rsc
DELTA=11 (3 added, 5 deleted, 3 changed)
OCL=35583
CL=35583
-rw-r--r-- | src/pkg/gob/decode.go | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/pkg/gob/decode.go b/src/pkg/gob/decode.go index 415b4b677..f7cff5836 100644 --- a/src/pkg/gob/decode.go +++ b/src/pkg/gob/decode.go @@ -355,18 +355,16 @@ type decEngine struct { } func decodeStruct(engine *decEngine, rtyp *reflect.StructType, b *bytes.Buffer, p uintptr, indir int) os.Error { - for ; indir > 0; indir-- { + if indir > 0 { up := unsafe.Pointer(p); + if indir > 1 { + up = decIndirect(up, indir) + } if *(*unsafe.Pointer)(up) == nil { // Allocate object by making a slice of bytes and recording the // address of the beginning of the array. TODO(rsc). - if indir > 1 { // allocate a pointer - b := make([]byte, unsafe.Sizeof((*int)(nil))); - *(*unsafe.Pointer)(up) = unsafe.Pointer(&b[0]); - } else { // allocate a struct - b := make([]byte, rtyp.Size()); - *(*unsafe.Pointer)(up) = unsafe.Pointer(&b[0]); - } + b := make([]byte, rtyp.Size()); + *(*unsafe.Pointer)(up) = unsafe.Pointer(&b[0]); } p = *(*uintptr)(up); } |