compile_norace.go 587 B

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