Remove dummy field for keeping reference of pointer

This commit is contained in:
Masaaki Goshima 2020-11-19 12:54:43 +09:00
parent fd7a72c0b8
commit ce1f865330
2 changed files with 1 additions and 11 deletions

View File

@ -6,8 +6,7 @@ import (
)
type interfaceDecoder struct {
typ *rtype
dummy unsafe.Pointer // for escape value
typ *rtype
}
func newInterfaceDecoder(typ *rtype) *interfaceDecoder {
@ -40,7 +39,6 @@ func (d *interfaceDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
case '{':
var v map[string]interface{}
ptr := unsafe.Pointer(&v)
d.dummy = ptr
if err := newMapDecoder(
interfaceMapType,
newStringDecoder(),
@ -53,7 +51,6 @@ func (d *interfaceDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
case '[':
var v []interface{}
ptr := unsafe.Pointer(&v)
d.dummy = ptr // escape ptr
if err := newSliceDecoder(
newInterfaceDecoder(d.typ),
d.typ,
@ -122,7 +119,6 @@ func (d *interfaceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (i
case '{':
var v map[string]interface{}
ptr := unsafe.Pointer(&v)
d.dummy = ptr
dec := newMapDecoder(
interfaceMapType,
newStringDecoder(),
@ -137,7 +133,6 @@ func (d *interfaceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (i
case '[':
var v []interface{}
ptr := unsafe.Pointer(&v)
d.dummy = ptr // escape ptr
dec := newSliceDecoder(
newInterfaceDecoder(d.typ),
d.typ,

View File

@ -8,7 +8,6 @@ type mapDecoder struct {
mapType *rtype
keyDecoder decoder
valueDecoder decoder
dummy *interfaceHeader
}
func newMapDecoder(mapType *rtype, keyDec decoder, valueDec decoder) *mapDecoder {
@ -28,25 +27,21 @@ func mapassign(t *rtype, m unsafe.Pointer, key, val unsafe.Pointer)
func (d *mapDecoder) setKey(buf []byte, cursor int64, key interface{}) (int64, error) {
header := (*interfaceHeader)(unsafe.Pointer(&key))
d.dummy = header
return d.keyDecoder.decode(buf, cursor, header.ptr)
}
func (d *mapDecoder) setValue(buf []byte, cursor int64, key interface{}) (int64, error) {
header := (*interfaceHeader)(unsafe.Pointer(&key))
d.dummy = header
return d.valueDecoder.decode(buf, cursor, header.ptr)
}
func (d *mapDecoder) setKeyStream(s *stream, key interface{}) error {
header := (*interfaceHeader)(unsafe.Pointer(&key))
d.dummy = header
return d.keyDecoder.decodeStream(s, header.ptr)
}
func (d *mapDecoder) setValueStream(s *stream, key interface{}) error {
header := (*interfaceHeader)(unsafe.Pointer(&key))
d.dummy = header
return d.valueDecoder.decodeStream(s, header.ptr)
}