1// +build !race
2
3package decoder
4
5import (
6	"unsafe"
7
8	"github.com/goccy/go-json/internal/runtime"
9)
10
11func CompileToGetDecoder(typ *runtime.Type) (Decoder, error) {
12	typeptr := uintptr(unsafe.Pointer(typ))
13	if typeptr > typeAddr.MaxTypeAddr {
14		return compileToGetDecoderSlowPath(typeptr, typ)
15	}
16
17	index := (typeptr - typeAddr.BaseTypeAddr) >> typeAddr.AddrShift
18	if dec := cachedDecoder[index]; dec != nil {
19		return dec, nil
20	}
21
22	dec, err := compileHead(typ, map[uintptr]Decoder{})
23	if err != nil {
24		return nil, err
25	}
26	cachedDecoder[index] = dec
27	return dec, nil
28}
29