mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:10:54 +00:00
Improve json coding performance
This commit is contained in:
parent
1d49a4bcbd
commit
393e4c4969
@ -331,16 +331,17 @@ func (output *BeegoOutput) IsServerError() bool {
|
|||||||
|
|
||||||
func stringsToJSON(str string) string {
|
func stringsToJSON(str string) string {
|
||||||
rs := []rune(str)
|
rs := []rune(str)
|
||||||
jsons := ""
|
var jsons bytes.Buffer
|
||||||
for _, r := range rs {
|
for _, r := range rs {
|
||||||
rint := int(r)
|
rint := int(r)
|
||||||
if rint < 128 {
|
if rint < 128 {
|
||||||
jsons += string(r)
|
jsons.WriteRune(r)
|
||||||
} else {
|
} else {
|
||||||
jsons += "\\u" + strconv.FormatInt(int64(rint), 16) // json
|
jsons.WriteString("\\u")
|
||||||
|
jsons.WriteString(strconv.FormatInt(int64(rint), 16))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return jsons
|
return jsons.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session sets session item value with given key.
|
// Session sets session item value with given key.
|
||||||
|
Loading…
Reference in New Issue
Block a user