>From docs:

macro r_str(p)
> Regex(p)
> end
>
>
> That’s all. This macro says that the literal contents of the string 
> literal r"^\s*(?:#|$)" should be passed to the
> @r_str macro and the result of that expansion should be placed in the 
> syntax tree where the string literal occurs. In
> other words, the expression r"^\s*(?:#|$)" is equivalent to placing the 
> following object directly into the syntax
> tree:
> Regex("^\\s*(?:#|\$)")
>
>
> Not only is the string literal form shorter and far more convenient, but 
> it is also more efficient: since the regular
> expression is compiled and the Regex object is actually created when the 
> code is compiled, the compilation occurs
> only once, rather than every time the code is executed. Consider if the 
> regular expression occurs in a loop:
> for line = lines
> m = match(r"^\s*(?:#|$)", line)
> if m == nothing
> # non-comment
> else
> # comment
> end
> end
>
> Shouldn't the compiler optimize this code *on its own* like this ? 
re = Regex("^\\s*(?:#|\$)")
for line = lines
m = match(re, line)
if m == nothing
# non-comment
else
# comment
end
end

This is kind of optimization which is really easy to detect and and execute.
How is that so that julia is not able to do that?


Reply via email to