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