@@ -14,7 +14,7 @@ type stateMachine struct {
1414 tokens []string
1515}
1616
17- // stateMachinePool provides a pool of reusable state machines for performance
17+ // stateMachinePool provides a pool of reusable state machines for performance.
1818var stateMachinePool = & sync.Pool {
1919 New : func () interface {} {
2020 return & stateMachine {
@@ -23,14 +23,14 @@ var stateMachinePool = &sync.Pool{
2323 },
2424}
2525
26- // tokenBufPool provides a pool of token buffers for better memory efficiency
26+ // tokenBufPool provides a pool of token buffers for better memory efficiency.
2727var tokenBufPool = sync.Pool {
2828 New : func () interface {} {
2929 return make ([]string , 0 , defaultTokenBufferCapacity )
3030 },
3131}
3232
33- // getStateMachine gets a state machine from the pool
33+ // getStateMachine gets a state machine from the pool.
3434func getStateMachine (text string ) * stateMachine {
3535 sm := stateMachinePool .Get ().(* stateMachine )
3636 sm .input = []rune (text )
@@ -39,7 +39,7 @@ func getStateMachine(text string) *stateMachine {
3939 return sm
4040}
4141
42- // putStateMachine returns a state machine to the pool
42+ // putStateMachine returns a state machine to the pool.
4343func putStateMachine (sm * stateMachine ) {
4444 // Clear references to allow GC
4545 sm .input = nil
@@ -68,7 +68,7 @@ func Tokenize(text string) []string {
6868
6969 // Return token buffer to pool
7070 if cap (sm .tokens ) <= 1024 {
71- tokenBufPool .Put (sm .tokens [:0 ])
71+ tokenBufPool .Put (sm .tokens [:0 ]) // #nosec - slice header is small, not worth pointer optimization
7272 }
7373
7474 // Return state machine to pool
@@ -89,15 +89,15 @@ func newStateMachine(text string) *stateMachine {
8989 }
9090}
9191
92- // tokenizeWithStateMachine processes the input according to the JS regex pattern
92+ // tokenizeWithStateMachine processes the input according to the JS regex pattern.
9393func (sm * stateMachine ) tokenizeWithStateMachine () []string {
9494 for sm .position < len (sm .input ) {
9595 sm .matchNext ()
9696 }
9797 return sm .tokens
9898}
9999
100- // matchNext tries to match the next token according to the pattern
100+ // matchNext tries to match the next token according to the pattern.
101101func (sm * stateMachine ) matchNext () {
102102 if sm .position >= len (sm .input ) {
103103 return
@@ -146,7 +146,7 @@ func (sm *stateMachine) matchNext() {
146146 sm .position ++
147147}
148148
149- // tryContraction matches contractions
149+ // tryContraction matches contractions.
150150func (sm * stateMachine ) tryContraction () string {
151151 if sm .position >= len (sm .input ) || sm .input [sm .position ] != '\'' {
152152 return ""
@@ -166,7 +166,7 @@ func (sm *stateMachine) tryContraction() string {
166166 return ""
167167}
168168
169- // tryWordWithPrefix matches [^\r\n\p{L}\p{N}]?\p{L}+
169+ // tryWordWithPrefix matches [^\r\n\p{L}\p{N}]?\p{L}+.
170170func (sm * stateMachine ) tryWordWithPrefix () string {
171171 start := sm .position
172172
@@ -193,7 +193,7 @@ func (sm *stateMachine) tryWordWithPrefix() string {
193193 return string (sm .input [start :sm .position ])
194194}
195195
196- // tryNumbers matches \p{N}{1,3}
196+ // tryNumbers matches \p{N}{1,3}.
197197func (sm * stateMachine ) tryNumbers () string {
198198 if sm .position >= len (sm .input ) || ! isNumber (sm .input [sm .position ]) {
199199 return ""
@@ -209,7 +209,7 @@ func (sm *stateMachine) tryNumbers() string {
209209 return string (sm .input [start :sm .position ])
210210}
211211
212- // tryPunctuationWithSpace matches ?[^\s\p{L}\p{N}]+[\r\n]*
212+ // tryPunctuationWithSpace matches ?[^\s\p{L}\p{N}]+[\r\n]*.
213213func (sm * stateMachine ) tryPunctuationWithSpace () string {
214214 start := sm .position
215215
@@ -249,7 +249,7 @@ func (sm *stateMachine) tryPunctuationWithSpace() string {
249249 return string (sm .input [start :sm .position ])
250250}
251251
252- // tryNewlineSequence matches \s*[\r\n]+
252+ // tryNewlineSequence matches \s*[\r\n]+.
253253func (sm * stateMachine ) tryNewlineSequence () string {
254254 start := sm .position
255255
@@ -277,7 +277,7 @@ func (sm *stateMachine) tryNewlineSequence() string {
277277 return string (sm .input [start :sm .position ])
278278}
279279
280- // tryWhitespace matches \s+(?!\S) or \s+
280+ // tryWhitespace matches \s+(?!\S) or \s+.
281281func (sm * stateMachine ) tryWhitespace () string {
282282 if sm .position >= len (sm .input ) || ! isWhitespace (sm .input [sm .position ]) {
283283 return ""
@@ -302,7 +302,7 @@ func (sm *stateMachine) tryWhitespace() string {
302302 return string (sm .input [start :sm .position ])
303303}
304304
305- // matchesAt checks if a string matches at current position (case-insensitive if specified)
305+ // matchesAt checks if a string matches at current position (case-insensitive if specified).
306306func (sm * stateMachine ) matchesAt (s string , caseInsensitive bool ) bool {
307307 runes := []rune (s )
308308 if sm .position + len (runes ) > len (sm .input ) {
@@ -325,7 +325,7 @@ func (sm *stateMachine) matchesAt(s string, caseInsensitive bool) bool {
325325 return true
326326}
327327
328- // Character classification helpers
328+ // Character classification helpers.
329329func isLetter (r rune ) bool {
330330 return unicode .IsLetter (r )
331331}
0 commit comments