Fix potential code bloat

This commit is contained in:
Flaviu Tamas
2015-05-26 20:29:12 -04:00
parent ca81749f2a
commit 3bbbb1a682

View File

@@ -305,10 +305,11 @@ proc toTable*(pattern: CaptureBounds, default = none(Slice[int])):
template itemsImpl(cond: bool): stmt {.immediate, dirty.} =
for i in 0 .. <RegexMatch(pattern).pattern.captureCount:
let nextVal = pattern[i]
if cond:
yield default
else:
yield nextVal
# done in this roundabout way to avoid multiple yields (potential code
# bloat)
let nextYieldVal = if cond: default else: nextVal
yield nextYieldVal
iterator items*(pattern: CaptureBounds, default = none(Slice[int])): Option[Slice[int]] =
itemsImpl(nextVal.isNone)