Fix potential code bloat
This commit is contained in:
parent
ca81749f2a
commit
3bbbb1a682
1 changed files with 5 additions and 4 deletions
|
|
@ -305,10 +305,11 @@ proc toTable*(pattern: CaptureBounds, default = none(Slice[int])):
|
||||||
template itemsImpl(cond: bool): stmt {.immediate, dirty.} =
|
template itemsImpl(cond: bool): stmt {.immediate, dirty.} =
|
||||||
for i in 0 .. <RegexMatch(pattern).pattern.captureCount:
|
for i in 0 .. <RegexMatch(pattern).pattern.captureCount:
|
||||||
let nextVal = pattern[i]
|
let nextVal = pattern[i]
|
||||||
if cond:
|
# done in this roundabout way to avoid multiple yields (potential code
|
||||||
yield default
|
# bloat)
|
||||||
else:
|
let nextYieldVal = if cond: default else: nextVal
|
||||||
yield nextVal
|
yield nextYieldVal
|
||||||
|
|
||||||
|
|
||||||
iterator items*(pattern: CaptureBounds, default = none(Slice[int])): Option[Slice[int]] =
|
iterator items*(pattern: CaptureBounds, default = none(Slice[int])): Option[Slice[int]] =
|
||||||
itemsImpl(nextVal.isNone)
|
itemsImpl(nextVal.isNone)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue