Skip to content

Commit f759b97

Browse files
committed
transitions z count
1 parent c5594f8 commit f759b97

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/nregex/dfamacro.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,15 @@ func matchImpl*(
305305
iPrev = start
306306
# workaround for VM registry limitation
307307
const
308-
tzLen = regex.transitions.z.len
309-
groupTransitionsLen = regex.groupsCount * 2
308+
zCount = regex.transitions.zCount
309+
zGroupsCount = regex.groupsCount * 2
310310
noCaptures = mfNoCaptures in flags
311311
# workaround for https://github.com/nim-lang/Nim/issues/13252
312312
const
313313
reFlags = regex.flags
314314
canSkipTransitionsZ = noCaptures and
315-
groupTransitionsLen == tzLen
316-
hasTransitionsZ = tzLen > 0 and
315+
zGroupsCount == zCount
316+
hasTransitionsZ = zCount > 0 and
317317
not canSkipTransitionsZ
318318
groupCount {.used.} = regex.groupsCount
319319
namedGroups {.used.} = regex.namedGroups

src/nregex/dfamatch.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ func matchImpl*(
244244
let
245245
asciiMode = reAscii in regex.flags
246246
canSkipTransitionsZ = mfNoCaptures in flags and
247-
regex.groupsCount * 2 == regex.transitions.z.len
248-
hasTransitionsZ = regex.transitions.z.len > 0 and
247+
regex.groupsCount * 2 == regex.transitions.zCount
248+
hasTransitionsZ = regex.transitions.zCount > 0 and
249249
not canSkipTransitionsZ
250250
var
251251
smA: Submatches

src/nregex/nfa.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ func isTransitionZ(n: Node): bool {.inline.} =
172172
else:
173173
false
174174

175+
func countTransitionsZ(nfa: seq[Node]): int =
176+
result = 0
177+
for n in nfa:
178+
result += int(n.isTransitionZ)
179+
175180
func teClosure(
176181
result: var TeClosure,
177182
nfa: seq[Node],
@@ -208,6 +213,7 @@ type
208213
all*: TransitionsAll
209214
allZ*: TransitionsAll
210215
z*: ZclosureStates
216+
zCount*: int
211217

212218
# XXX do not add char classes transitions \w, \d, etc in ascii mode
213219
func eRemoval(
@@ -261,6 +267,9 @@ func eRemoval(
261267
qw.addFirst(qb)
262268
transitions.all.setLen(statePos)
263269
transitions.allZ.setLen(statePos)
270+
if transitions.z.len == 0:
271+
transitions.allZ = @[]
272+
transitions.zCount = eNfa.countTransitionsZ
264273
result = newSeq[Node](statePos)
265274
for en, nn in statesMap.pairs:
266275
if nn == -1:

0 commit comments

Comments
 (0)