mirror of
https://github.com/golang/go
synced 2024-11-26 19:51:17 -07:00
undo CL 14154043 / 3e485428767e
««« original CL description encoding/gob: do not hide pointer argument for the garbage collector R=golang-dev, r CC=golang-dev https://golang.org/cl/14154043 »»» R=golang-dev CC=golang-dev https://golang.org/cl/14165043
This commit is contained in:
parent
6ffd70e7f0
commit
7a480a8c9b
@ -654,19 +654,21 @@ func (dec *Decoder) ignoreMap(state *decoderState, keyOp, elemOp decOp) {
|
||||
|
||||
// decodeSlice decodes a slice and stores the slice header through p.
|
||||
// Slices are encoded as an unsigned length followed by the elements.
|
||||
func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p unsafe.Pointer, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl error) {
|
||||
func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl error) {
|
||||
nr := state.decodeUint()
|
||||
n := int(nr)
|
||||
if indir > 0 {
|
||||
if *(*unsafe.Pointer)(p) == nil {
|
||||
up := unsafe.Pointer(p)
|
||||
if *(*unsafe.Pointer)(up) == nil {
|
||||
// Allocate the slice header.
|
||||
*(*unsafe.Pointer)(p) = unsafe.Pointer(new([]unsafe.Pointer))
|
||||
*(*unsafe.Pointer)(up) = unsafe.Pointer(new([]unsafe.Pointer))
|
||||
}
|
||||
p = *(*uintptr)(up)
|
||||
}
|
||||
// Allocate storage for the slice elements, that is, the underlying array,
|
||||
// if the existing slice does not have the capacity.
|
||||
// Always write a header at p.
|
||||
hdrp := (*reflect.SliceHeader)(p)
|
||||
hdrp := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
||||
if hdrp.Cap < n {
|
||||
hdrp.Data = reflect.MakeSlice(atyp, n, n).Pointer()
|
||||
hdrp.Cap = n
|
||||
@ -885,7 +887,7 @@ func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProg
|
||||
elemOp, elemIndir := dec.decOpFor(elemId, t.Elem(), name, inProgress)
|
||||
ovfl := overflow(name)
|
||||
op = func(i *decInstr, state *decoderState, p unsafe.Pointer) {
|
||||
state.dec.decodeSlice(t, state, p, *elemOp, t.Elem().Size(), i.indir, elemIndir, ovfl)
|
||||
state.dec.decodeSlice(t, state, uintptr(p), *elemOp, t.Elem().Size(), i.indir, elemIndir, ovfl)
|
||||
}
|
||||
|
||||
case reflect.Struct:
|
||||
|
Loading…
Reference in New Issue
Block a user