mirror of
https://github.com/go-gitea/gitea
synced 2024-11-07 10:44:26 +00:00
1790f01dd9
* Upgrade xorm to v1.2.2 (#16663) Backport #16663 Fix #16683 * Add test to ensure that dumping of login sources remains correct (#16847) #16831 has occurred because of a missed regression. This PR adds a simple test to try to prevent this occuring again. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
37 lines
681 B
Go
Vendored
37 lines
681 B
Go
Vendored
// +build race
|
|
|
|
package decoder
|
|
|
|
import (
|
|
"sync"
|
|
"unsafe"
|
|
|
|
"github.com/goccy/go-json/internal/runtime"
|
|
)
|
|
|
|
var decMu sync.RWMutex
|
|
|
|
func CompileToGetDecoder(typ *runtime.Type) (Decoder, error) {
|
|
typeptr := uintptr(unsafe.Pointer(typ))
|
|
if typeptr > typeAddr.MaxTypeAddr {
|
|
return compileToGetDecoderSlowPath(typeptr, typ)
|
|
}
|
|
|
|
index := (typeptr - typeAddr.BaseTypeAddr) >> typeAddr.AddrShift
|
|
decMu.RLock()
|
|
if dec := cachedDecoder[index]; dec != nil {
|
|
decMu.RUnlock()
|
|
return dec, nil
|
|
}
|
|
decMu.RUnlock()
|
|
|
|
dec, err := compileHead(typ, map[uintptr]Decoder{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
decMu.Lock()
|
|
cachedDecoder[index] = dec
|
|
decMu.Unlock()
|
|
return dec, nil
|
|
}
|