1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 10:18:38 +00:00

Migrate to use jsoniter instead of encoding/json (#14841)

* Migrate to use jsoniter

* fix tests

* update gitea.com/go-chi/binding

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
zeripath
2021-03-01 21:08:10 +00:00
committed by GitHub
parent 59fd641d1f
commit f0e15250b9
77 changed files with 264 additions and 82 deletions

View File

@@ -38,6 +38,7 @@ import (
mirror_service "code.gitea.io/gitea/services/mirror"
"github.com/editorconfig/editorconfig-core-go/v2"
jsoniter "github.com/json-iterator/go"
)
// Used from static.go && dynamic.go
@@ -45,6 +46,7 @@ var mailSubjectSplit = regexp.MustCompile(`(?m)^-{3,}[\s]*$`)
// NewFuncMap returns functions for injecting to templates
func NewFuncMap() []template.FuncMap {
jsonED := jsoniter.ConfigCompatibleWithStandardLibrary
return []template.FuncMap{map[string]interface{}{
"GoVer": func() string {
return strings.Title(runtime.Version())
@@ -215,7 +217,7 @@ func NewFuncMap() []template.FuncMap {
return fmt.Sprintf("%f", float64(adds)/(float64(adds)+float64(dels))*100)
},
"Json": func(in interface{}) string {
out, err := json.Marshal(in)
out, err := jsonED.Marshal(in)
if err != nil {
return ""
}
@@ -814,6 +816,8 @@ func ActionIcon(opType models.ActionType) string {
// ActionContent2Commits converts action content to push commits
func ActionContent2Commits(act Actioner) *repository.PushCommits {
push := repository.NewPushCommits()
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal([]byte(act.GetContent()), push); err != nil {
log.Error("json.Unmarshal:\n%s\nERROR: %v", act.GetContent(), err)
}