summary refs log tree commit diff stats
path: root/lib/impure
diff options
context:
space:
mode:
authorFlaviu Tamas <tamasflaviu@gmail.com>2015-05-26 20:29:12 -0400
committerFlaviu Tamas <tamasflaviu@gmail.com>2015-06-07 13:13:05 -0400
commit3bbbb1a6825c5bcff2d4dfc41c1cebff83751498 (patch)
tree2de118e5de379de5df760b04fb1a9546eb4632d9 /lib/impure
parentca81749f2ab3af9d3d86b865c2e4dfa116f7aad3 (diff)
downloadNim-3bbbb1a6825c5bcff2d4dfc41c1cebff83751498.tar.gz
Fix potential code bloat
Diffstat (limited to 'lib/impure')
-rw-r--r--lib/impure/nre.nim9
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)