@@ -200,7 +200,7 @@ template longestMatchEnter(): untyped {.dirty.} =
200200 if symEoe in regex.dfa.table[q]:
201201 matchedLong = true
202202 iPrevLong = iPrev
203- if regex.transitions.z.len > 0 :
203+ if hasTransitionsZ :
204204 submatch (
205205 smA, smB, capts, regex.transitions,
206206 regex.dfa.cs[regex.dfa.closures[q][symEoe]], iPrev, cPrev, c.int32 )
@@ -210,7 +210,7 @@ template longestMatchEnter(): untyped {.dirty.} =
210210
211211template longestMatchExit (): untyped {.dirty .} =
212212 result = matchedLong
213- if regex.transitions.z.len > 0 :
213+ if hasTransitionsZ :
214214 constructSubmatches (m.captures, capts, captLong, regex.groupsCount)
215215 if regex.namedGroups.len > 0 :
216216 m.namedGroups = regex.namedGroups
@@ -219,7 +219,7 @@ template longestMatchExit(): untyped {.dirty.} =
219219
220220template shortestMatch (): untyped {.dirty .} =
221221 if symEoe in regex.dfa.table[q]:
222- if regex.transitions.z.len > 0 :
222+ if hasTransitionsZ :
223223 submatch (
224224 smA, smB, capts, regex.transitions,
225225 regex.dfa.cs[regex.dfa.closures[q][symEoe]], iPrev, cPrev, c.int32 )
@@ -241,7 +241,12 @@ func matchImpl*(
241241 # echo dfa
242242 m.clear ()
243243 result = false
244- let asciiMode = reAscii in regex.flags
244+ let
245+ asciiMode = reAscii in regex.flags
246+ canSkipTransitionsZ = mfNoCaptures in flags and
247+ regex.groupsCount * 2 == regex.transitions.z.len
248+ hasTransitionsZ = regex.transitions.z.len > 0 and
249+ not canSkipTransitionsZ
245250 var
246251 smA: Submatches
247252 smB: Submatches
@@ -257,7 +262,7 @@ func matchImpl*(
257262 matchedLong {.used .} = false
258263 captLong {.used .} = - 1
259264 iPrevLong {.used .} = start
260- if regex.transitions.z.len > 0 :
265+ if hasTransitionsZ :
261266 smA = newSubmatches ()
262267 smB = newSubmatches ()
263268 smA.add ((0 'i16 , - 1 'i32 ))
@@ -283,7 +288,7 @@ func matchImpl*(
283288 longestMatchExit ()
284289 else :
285290 return
286- if regex.transitions.z.len > 0 :
291+ if hasTransitionsZ :
287292 submatch (
288293 smA, smB, capts, regex.transitions,
289294 regex.dfa.cs[regex.dfa.closures[q][cSym]], iPrev, cPrev, c.int32 )
@@ -296,7 +301,7 @@ func matchImpl*(
296301 when mfLongestMatch in flags:
297302 longestMatchExit ()
298303 return
299- if regex.transitions.z.len > 0 :
304+ if hasTransitionsZ :
300305 submatch (
301306 smA, smB, capts, regex.transitions,
302307 regex.dfa.cs[regex.dfa.closures[q][symEoe]], iPrev, cPrev, - 1 'i32 )
0 commit comments