aboutsummaryrefslogtreecommitdiff
path: root/bytesconv.go
diff options
context:
space:
mode:
authorGravatar ZhangYunHao <zhangyunhao116@gmail.com> 2022-03-17 21:52:47 +0800
committerGravatar GitHub <noreply@github.com> 2022-03-17 14:52:47 +0100
commit31019388508011fa6474f60c5e097680037f63f4 (patch)
tree9066fcd548a0c7f67ddddac77ed9413f65fce2b6 /bytesconv.go
parentbytesconv: add appropriate build tags for s390x (#1250) (diff)
downloadfasthttp-31019388508011fa6474f60c5e097680037f63f4.tar.gz
fasthttp-31019388508011fa6474f60c5e097680037f63f4.tar.bz2
fasthttp-31019388508011fa6474f60c5e097680037f63f4.zip
Imporve AppendHTMLEscape fast path (#1249)
Diffstat (limited to 'bytesconv.go')
-rw-r--r--bytesconv.go17
1 files changed, 4 insertions, 13 deletions
diff --git a/bytesconv.go b/bytesconv.go
index a35b606..a12bb95 100644
--- a/bytesconv.go
+++ b/bytesconv.go
@@ -11,7 +11,6 @@ import (
"math"
"net"
"reflect"
- "strings"
"sync"
"time"
"unsafe"
@@ -19,19 +18,11 @@ import (
// AppendHTMLEscape appends html-escaped s to dst and returns the extended dst.
func AppendHTMLEscape(dst []byte, s string) []byte {
- if strings.IndexByte(s, '&') < 0 &&
- strings.IndexByte(s, '<') < 0 &&
- strings.IndexByte(s, '>') < 0 &&
- strings.IndexByte(s, '"') < 0 &&
- strings.IndexByte(s, '\'') < 0 {
-
- // fast path - nothing to escape
- return append(dst, s...)
- }
+ var (
+ prev int
+ sub string
+ )
- // slow path
- var prev int
- var sub string
for i, n := 0, len(s); i < n; i++ {
sub = ""
switch s[i] {