compile_norace.go 602 B

123456789101112131415161718192021222324252627282930
  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. initDecoder()
  10. typeptr := uintptr(unsafe.Pointer(typ))
  11. if typeptr > typeAddr.MaxTypeAddr {
  12. return compileToGetDecoderSlowPath(typeptr, typ)
  13. }
  14. index := (typeptr - typeAddr.BaseTypeAddr) >> typeAddr.AddrShift
  15. if dec := cachedDecoder[index]; dec != nil {
  16. return dec, nil
  17. }
  18. dec, err := compileHead(typ, map[uintptr]Decoder{})
  19. if err != nil {
  20. return nil, err
  21. }
  22. cachedDecoder[index] = dec
  23. return dec, nil
  24. }