2021-02-04 12:00:08 +03:00
|
|
|
// +build !race
|
|
|
|
|
|
|
|
package json
|
|
|
|
|
2021-02-10 19:15:31 +03:00
|
|
|
import "unsafe"
|
|
|
|
|
|
|
|
func decodeCompileToGetDecoder(typ *rtype) (decoder, error) {
|
|
|
|
typeptr := uintptr(unsafe.Pointer(typ))
|
2021-02-09 15:37:18 +03:00
|
|
|
if typeptr > maxTypeAddr {
|
2021-02-10 18:33:54 +03:00
|
|
|
return decodeCompileToGetDecoderSlowPath(typeptr, typ)
|
2021-02-04 12:00:08 +03:00
|
|
|
}
|
|
|
|
|
2021-05-04 03:00:10 +03:00
|
|
|
index := (typeptr - baseTypeAddr) >> typeAddrShift
|
2021-02-04 12:00:08 +03:00
|
|
|
if dec := cachedDecoder[index]; dec != nil {
|
|
|
|
return dec, nil
|
|
|
|
}
|
|
|
|
|
2021-02-10 18:33:54 +03:00
|
|
|
dec, err := decodeCompileHead(typ, map[uintptr]decoder{})
|
2021-02-04 12:00:08 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cachedDecoder[index] = dec
|
|
|
|
return dec, nil
|
|
|
|
}
|