mirror of https://github.com/goccy/go-json.git
32 lines
584 B
Go
32 lines
584 B
Go
|
// +build race
|
||
|
|
||
|
package json
|
||
|
|
||
|
import "sync"
|
||
|
|
||
|
var decMu sync.RWMutex
|
||
|
|
||
|
func (d *Decoder) compileToGetDecoder(typeptr uintptr, typ *rtype) (decoder, error) {
|
||
|
if !existsCachedDecoder {
|
||
|
return d.compileToGetDecoderSlowPath(typeptr, typ)
|
||
|
}
|
||
|
|
||
|
index := typeptr - baseTypeAddr
|
||
|
decMu.RLock()
|
||
|
if dec := cachedDecoder[index]; dec != nil {
|
||
|
decMu.RUnlock()
|
||
|
return dec, nil
|
||
|
}
|
||
|
decMu.RUnlock()
|
||
|
|
||
|
d.structTypeToDecoder = map[uintptr]decoder{}
|
||
|
dec, err := d.compileHead(typ)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
decMu.Lock()
|
||
|
cachedDecoder[index] = dec
|
||
|
decMu.Unlock()
|
||
|
return dec, nil
|
||
|
}
|