Skip to content

Commit

Permalink
added note to re constructor regarding performance (#13224)
Browse files Browse the repository at this point in the history
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 :)
  • Loading branch information
whiterock authored and Araq committed Jan 22, 2020
1 parent 2fad7f1 commit ef9fb39
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/impure/re.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ef9fb39

Please sign in to comment.