Skip to content

Commit 51e044b

Browse files
committed
smaller captNode
1 parent 7cf9eb6 commit 51e044b

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/nregex/private/dfamatch.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import dfa
1616

1717
type
1818
CaptNode* = object
19-
parent*: int
19+
parent*: int32
2020
bound*: int
21-
idx*: int
21+
idx*: int16
2222
Capts* = seq[CaptNode]
2323
Captures* = seq[seq[Slice[int]]]
2424

src/nregex/private/nodematch.nim

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import std/sets
33

44
import pkg/unicodedb/properties
55
import pkg/unicodedb/types
6-
import pkg/unicodeplus except isUpper, isLower
6+
import pkg/unicodeplus
77

88
import nodetype
99
import common
@@ -23,12 +23,9 @@ func isWordAscii(r: Rune): bool {.inline.} =
2323
else:
2424
false
2525

26-
template isWordBoundaryImpl(r, nxt, alnumProc): bool =
27-
let
28-
isWord = r != invalidRune and alnumProc(r)
29-
isNxtWord = nxt != invalidRune and alnumProc(nxt)
30-
((isWord and not isNxtWord) or
31-
(not isWord and isNxtWord))
26+
template isWordBoundaryImpl(r, nxt, isWordProc): bool =
27+
(r.int > -1 and isWordProc(r)) xor
28+
(nxt.int > -1 and isWordProc(nxt))
3229

3330
func isWordBoundary(r: Rune, nxt: Rune): bool {.inline.} =
3431
## check if current match
@@ -108,17 +105,11 @@ func isAnyAscii(r: Rune): bool {.inline.} =
108105
(r.int <= int8.high and
109106
r != lineBreakRune)
110107

111-
# todo: can not use unicodeplus due to
112-
# https://github.com/nim-lang/Nim/issues/7059
113-
func swapCase*(r: Rune): Rune =
114-
# Note a character can be
115-
# non-lower and non-upper
116-
if r.isUpper():
117-
result = r.toLower()
118-
elif r.isLower():
119-
result = r.toUpper()
120-
else:
121-
result = r
108+
func swapCase(r: Rune): Rune =
109+
result = r.toLower()
110+
if result != r:
111+
return
112+
result = r.toUpper()
122113

123114
func match*(n: Node, r: Rune): bool =
124115
## match for ``Node`` of matchable kind.

0 commit comments

Comments
 (0)