forked from mirror/go-json
35 lines
807 B
Go
35 lines
807 B
Go
// +build !race
|
|
|
|
package json
|
|
|
|
import "unsafe"
|
|
|
|
func encodeCompileToGetCodeSet(typeptr uintptr) (*opcodeSet, error) {
|
|
if typeptr > maxTypeAddr {
|
|
return encodeCompileToGetCodeSetSlowPath(typeptr)
|
|
}
|
|
index := typeptr - baseTypeAddr
|
|
if codeSet := cachedOpcodeSets[index]; codeSet != nil {
|
|
return codeSet, nil
|
|
}
|
|
|
|
// noescape trick for header.typ ( reflect.*rtype )
|
|
copiedType := *(**rtype)(unsafe.Pointer(&typeptr))
|
|
|
|
code, err := encodeCompileHead(&encodeCompileContext{
|
|
typ: copiedType,
|
|
structTypeToCompiledCode: map[uintptr]*compiledCode{},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
code = copyOpcode(code)
|
|
codeLength := code.totalLength()
|
|
codeSet := &opcodeSet{
|
|
code: code,
|
|
codeLength: codeLength,
|
|
}
|
|
cachedOpcodeSets[index] = codeSet
|
|
return codeSet, nil
|
|
}
|