From 393e4c4969f62c71ce4d65a68fca96ea60e84b0e Mon Sep 17 00:00:00 2001 From: jiayukun Date: Wed, 22 Feb 2017 17:38:26 +0800 Subject: [PATCH] Improve json coding performance --- context/output.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/context/output.go b/context/output.go index 4b513dd8..564ef96d 100644 --- a/context/output.go +++ b/context/output.go @@ -331,16 +331,17 @@ func (output *BeegoOutput) IsServerError() bool { func stringsToJSON(str string) string { rs := []rune(str) - jsons := "" + var jsons bytes.Buffer for _, r := range rs { rint := int(r) if rint < 128 { - jsons += string(r) + jsons.WriteRune(r) } 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.