Skip to content

Commit 3101938

Browse files
Imporve AppendHTMLEscape fast path (#1249)
1 parent d1753f7 commit 3101938

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

bytesconv.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,18 @@ import (
1111
"math"
1212
"net"
1313
"reflect"
14-
"strings"
1514
"sync"
1615
"time"
1716
"unsafe"
1817
)
1918

2019
// AppendHTMLEscape appends html-escaped s to dst and returns the extended dst.
2120
func AppendHTMLEscape(dst []byte, s string) []byte {
22-
if strings.IndexByte(s, '&') < 0 &&
23-
strings.IndexByte(s, '<') < 0 &&
24-
strings.IndexByte(s, '>') < 0 &&
25-
strings.IndexByte(s, '"') < 0 &&
26-
strings.IndexByte(s, '\'') < 0 {
27-
28-
// fast path - nothing to escape
29-
return append(dst, s...)
30-
}
21+
var (
22+
prev int
23+
sub string
24+
)
3125

32-
// slow path
33-
var prev int
34-
var sub string
3526
for i, n := 0, len(s); i < n; i++ {
3627
sub = ""
3728
switch s[i] {

0 commit comments

Comments
 (0)