summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorwhiterock <whiterockftp@gmail.com>2020-01-22 16:02:16 +0100
committerAndreas Rumpf <rumpf_a@web.de>2020-01-22 16:02:16 +0100
commitef9fb39cdf4fa0f260ced0c5cccb1fafc7993e7a (patch)
treec86fb91e2330bc3f27a02ecd7d82abf77ede0659
parent2fad7f134fa8cf871cdf6ccdcedc6df0d62c2f64 (diff)
downloadNim-ef9fb39cdf4fa0f260ced0c5cccb1fafc7993e7a.tar.gz
added note to re constructor regarding performance (#13224)
Since I was new to regex I did not know that there is a compilation going on with ``re"[abc]"`` constructor and so I followed the other examples in the docs blindly, that is I just put the constructor directly in the arguments of match, find, etc., which was inside a loop and then wondered why my performance was so bad. Of course putting it outside the loop made it vastly more performant. People like me would benefit from the small note I added I would think :)
-rw-r--r--lib/impure/re.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/impure/re.nim b/lib/impure/re.nim
index a200f27b6..809180774 100644
--- a/lib/impure/re.nim
+++ b/lib/impure/re.nim
@@ -78,7 +78,11 @@ proc re*(s: string, flags = {reStudy}): Regex =
   ##
   ## Note that Nim's
   ## extended raw string literals support the syntax ``re"[abc]"`` as
-  ## a short form for ``re(r"[abc]")``.
+  ## a short form for ``re(r"[abc]")``. Also note that since this
+  ## compiles the regular expression, which is expensive, you should
+  ## avoid putting it directly in the arguments of the functions like
+  ## the examples show below if you plan to use it a lot of times, as
+  ## this will hurt performance immensely. (e.g. outside a loop, ...)
   when defined(gcDestructors):
     result = Regex()
   else: