diff options
author | Flaviu Tamas <tamasflaviu@gmail.com> | 2015-05-26 20:29:12 -0400 |
---|---|---|
committer | Flaviu Tamas <tamasflaviu@gmail.com> | 2015-06-07 13:13:05 -0400 |
commit | 3bbbb1a6825c5bcff2d4dfc41c1cebff83751498 (patch) | |
tree | 2de118e5de379de5df760b04fb1a9546eb4632d9 /lib/impure | |
parent | ca81749f2ab3af9d3d86b865c2e4dfa116f7aad3 (diff) | |
download | Nim-3bbbb1a6825c5bcff2d4dfc41c1cebff83751498.tar.gz |
Fix potential code bloat
Diffstat (limited to 'lib/impure')
-rw-r--r-- | lib/impure/nre.nim | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim index 6363f278a..bfe2ad33a 100644 --- a/lib/impure/nre.nim +++ b/lib/impure/nre.nim @@ -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) |