Add noescape trick for decoding

This commit is contained in:
Masaaki Goshima 2020-05-08 23:59:49 +09:00
parent df0365d82f
commit a979b83d27
2 changed files with 5 additions and 2 deletions

View File

@ -81,7 +81,10 @@ func (d *Decoder) decode(src []byte, header *interfaceHeader) error {
typeptr := uintptr(unsafe.Pointer(typ))
dec := cachedDecoder.get(typeptr)
if dec == nil {
compiledDec, err := d.compileHead(typ)
// noescape trick for header.typ ( reflect.*rtype )
copiedType := (*rtype)(unsafe.Pointer(typeptr))
compiledDec, err := d.compileHead(copiedType)
if err != nil {
return err
}

View File

@ -159,7 +159,7 @@ func (e *Encoder) encode(v interface{}) error {
return nil
}
// to noescape trick for header.typ ( reflect.*rtype )
// noescape trick for header.typ ( reflect.*rtype )
copiedType := (*rtype)(unsafe.Pointer(typeptr))
codeIndent, err := e.compileHead(copiedType, true)