2021-02-04 12:00:08 +03:00
|
|
|
// +build race
|
|
|
|
|
|
|
|
package json
|
|
|
|
|
2021-02-09 15:37:18 +03:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
2021-02-04 12:00:08 +03:00
|
|
|
|
|
|
|
var decMu sync.RWMutex
|
|
|
|
|
|
|
|
func (d *Decoder) compileToGetDecoder(typeptr uintptr, typ *rtype) (decoder, error) {
|
2021-02-09 15:37:18 +03:00
|
|
|
if typeptr > maxTypeAddr {
|
2021-02-04 12:00:08 +03:00
|
|
|
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
|
|
|
|
}
|