@@ -50,6 +50,7 @@ func (e *escapeStreamer) Text(data string) error {
50
50
_ , _ = sb .WriteString (data [:len (UTF8BOM )])
51
51
pos = len (UTF8BOM )
52
52
}
53
+ dataBytes := []byte (data )
53
54
for pos < len (data ) {
54
55
nextIdxs := defaultWordRegexp .FindStringIndex (data [pos :])
55
56
if nextIdxs == nil {
@@ -64,30 +65,30 @@ func (e *escapeStreamer) Text(data string) error {
64
65
positions := make ([]int , 0 , next - until + 1 )
65
66
66
67
for pos < until {
67
- r , sz := utf8 .DecodeRune ([] byte ( data ) [pos :])
68
+ r , sz := utf8 .DecodeRune (dataBytes [pos :])
68
69
positions = positions [:0 ]
69
70
positions = append (positions , pos , pos + sz )
70
71
types , confusables , _ := e .runeTypes (r )
71
- if err := e .handleRunes (data , []rune {r }, positions , types , confusables , sb ); err != nil {
72
+ if err := e .handleRunes (dataBytes , []rune {r }, positions , types , confusables , sb ); err != nil {
72
73
return err
73
74
}
74
75
pos += sz
75
76
}
76
77
77
78
for i := pos ; i < next ; {
78
- r , sz := utf8 .DecodeRune ([] byte ( data ) [i :])
79
+ r , sz := utf8 .DecodeRune (dataBytes [i :])
79
80
runes = append (runes , r )
80
81
positions = append (positions , i )
81
82
i += sz
82
83
}
83
84
positions = append (positions , next )
84
85
types , confusables , runeCounts := e .runeTypes (runes ... )
85
86
if runeCounts .needsEscape () {
86
- if err := e .handleRunes (data , runes , positions , types , confusables , sb ); err != nil {
87
+ if err := e .handleRunes (dataBytes , runes , positions , types , confusables , sb ); err != nil {
87
88
return err
88
89
}
89
90
} else {
90
- _ , _ = sb .Write ([] byte ( data ) [pos :next ])
91
+ _ , _ = sb .Write (dataBytes [pos :next ])
91
92
}
92
93
pos = next
93
94
}
@@ -99,7 +100,7 @@ func (e *escapeStreamer) Text(data string) error {
99
100
return nil
100
101
}
101
102
102
- func (e * escapeStreamer ) handleRunes (data string , runes []rune , positions []int , types []runeType , confusables []rune , sb * strings.Builder ) error {
103
+ func (e * escapeStreamer ) handleRunes (data [] byte , runes []rune , positions []int , types []runeType , confusables []rune , sb * strings.Builder ) error {
103
104
for i , r := range runes {
104
105
switch types [i ] {
105
106
case brokenRuneType :
@@ -111,7 +112,7 @@ func (e *escapeStreamer) handleRunes(data string, runes []rune, positions []int,
111
112
}
112
113
end := positions [i + 1 ]
113
114
start := positions [i ]
114
- if err := e .brokenRune ([] byte ( data ) [start :end ]); err != nil {
115
+ if err := e .brokenRune (data [start :end ]); err != nil {
115
116
return err
116
117
}
117
118
case ambiguousRuneType :
0 commit comments