diff --git a/decode.go b/decode.go index 923cdce..4cee2ac 100644 --- a/decode.go +++ b/decode.go @@ -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 } diff --git a/encode.go b/encode.go index e64780a..6a8db7a 100644 --- a/encode.go +++ b/encode.go @@ -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)