From a9e37932c4c43a8aaebed726c62c36615c137a98 Mon Sep 17 00:00:00 2001
From: Masaaki Goshima <goccy54@gmail.com>
Date: Sat, 15 Aug 2020 23:11:06 +0900
Subject: [PATCH] Refactor encodeEscapedString ( for improvement performance )

---
 encode_string.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/encode_string.go b/encode_string.go
index 93db0c0..8cd1228 100644
--- a/encode_string.go
+++ b/encode_string.go
@@ -219,21 +219,21 @@ var hex = "0123456789abcdef"
 
 func (e *Encoder) encodeEscapedString(s string) {
 	valLen := len(s)
-	e.buf = append(e.buf, '"')
 	// write string, the fast path, without utf8 and escape support
 	i := 0
 	for ; i < valLen; i++ {
 		c := s[i]
-		if c < utf8.RuneSelf && htmlSafeSet[c] {
-			e.buf = append(e.buf, c)
-		} else {
+		if c >= utf8.RuneSelf || !htmlSafeSet[c] {
 			break
 		}
 	}
+	e.buf = append(e.buf, '"')
 	if i == valLen {
+		e.buf = append(e.buf, s...)
 		e.buf = append(e.buf, '"')
 		return
 	}
+	e.buf = append(e.buf, s[:i]...)
 	e.writeStringSlowPathWithHTMLEscaped(i, s, valLen)
 }