mirror of
https://github.com/golang/go
synced 2024-11-12 07:40:23 -07:00
better code for allocation through indirection
R=rsc DELTA=11 (3 added, 5 deleted, 3 changed) OCL=35583 CL=35583
This commit is contained in:
parent
330ab5fddb
commit
c0e0f82e49
@ -355,18 +355,16 @@ type decEngine struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func decodeStruct(engine *decEngine, rtyp *reflect.StructType, b *bytes.Buffer, p uintptr, indir int) os.Error {
|
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);
|
up := unsafe.Pointer(p);
|
||||||
|
if indir > 1 {
|
||||||
|
up = decIndirect(up, indir)
|
||||||
|
}
|
||||||
if *(*unsafe.Pointer)(up) == nil {
|
if *(*unsafe.Pointer)(up) == nil {
|
||||||
// Allocate object by making a slice of bytes and recording the
|
// Allocate object by making a slice of bytes and recording the
|
||||||
// address of the beginning of the array. TODO(rsc).
|
// address of the beginning of the array. TODO(rsc).
|
||||||
if indir > 1 { // allocate a pointer
|
b := make([]byte, rtyp.Size());
|
||||||
b := make([]byte, unsafe.Sizeof((*int)(nil)));
|
*(*unsafe.Pointer)(up) = unsafe.Pointer(&b[0]);
|
||||||
*(*unsafe.Pointer)(up) = unsafe.Pointer(&b[0]);
|
|
||||||
} else { // allocate a struct
|
|
||||||
b := make([]byte, rtyp.Size());
|
|
||||||
*(*unsafe.Pointer)(up) = unsafe.Pointer(&b[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
p = *(*uintptr)(up);
|
p = *(*uintptr)(up);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user