2018-01-28 11:00:11 +02:00
|
|
|
//+build go1.9
|
|
|
|
|
|
|
|
package jsoniter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
type frozenConfig struct {
|
|
|
|
configBeforeFrozen Config
|
|
|
|
sortMapKeys bool
|
|
|
|
indentionStep int
|
|
|
|
objectFieldMustBeSimpleString bool
|
|
|
|
onlyTaggedField bool
|
2018-02-05 17:05:57 +02:00
|
|
|
disallowUnknownFields bool
|
2018-01-28 11:00:11 +02:00
|
|
|
decoderCache sync.Map
|
|
|
|
encoderCache sync.Map
|
|
|
|
extensions []Extension
|
2018-02-22 04:29:29 +02:00
|
|
|
streamPool *sync.Pool
|
|
|
|
iteratorPool *sync.Pool
|
2018-01-28 11:00:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cfg *frozenConfig) initCache() {
|
|
|
|
cfg.decoderCache = sync.Map{}
|
|
|
|
cfg.encoderCache = sync.Map{}
|
|
|
|
}
|
|
|
|
|
2018-02-22 04:12:08 +02:00
|
|
|
func (cfg *frozenConfig) addDecoderToCache(cacheKey uintptr, decoder ValDecoder) {
|
2018-01-28 11:00:11 +02:00
|
|
|
cfg.decoderCache.Store(cacheKey, decoder)
|
|
|
|
}
|
|
|
|
|
2018-02-22 04:12:08 +02:00
|
|
|
func (cfg *frozenConfig) addEncoderToCache(cacheKey uintptr, encoder ValEncoder) {
|
2018-01-28 11:00:11 +02:00
|
|
|
cfg.encoderCache.Store(cacheKey, encoder)
|
|
|
|
}
|
|
|
|
|
2018-02-22 04:12:08 +02:00
|
|
|
func (cfg *frozenConfig) getDecoderFromCache(cacheKey uintptr) ValDecoder {
|
2018-01-28 11:00:11 +02:00
|
|
|
decoder, found := cfg.decoderCache.Load(cacheKey)
|
|
|
|
if found {
|
|
|
|
return decoder.(ValDecoder)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-22 04:12:08 +02:00
|
|
|
func (cfg *frozenConfig) getEncoderFromCache(cacheKey uintptr) ValEncoder {
|
2018-01-28 11:00:11 +02:00
|
|
|
encoder, found := cfg.encoderCache.Load(cacheKey)
|
|
|
|
if found {
|
|
|
|
return encoder.(ValEncoder)
|
|
|
|
}
|
|
|
|
return nil
|
2018-02-05 15:43:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var cfgCache = &sync.Map{}
|
|
|
|
|
|
|
|
func getFrozenConfigFromCache(cfg Config) *frozenConfig {
|
|
|
|
obj, found := cfgCache.Load(cfg)
|
|
|
|
if found {
|
|
|
|
return obj.(*frozenConfig)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func addFrozenConfigToCache(cfg Config, frozenConfig *frozenConfig) {
|
|
|
|
cfgCache.Store(cfg, frozenConfig)
|
2018-02-05 16:45:04 +02:00
|
|
|
}
|