Re: [PATCH 13/16] send-email: extract_valid_address use qr// regexes and /o

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 13/16] send-email: extract_valid_address use qr// regexes and /o

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:49:40

Jeff King [off-list ref] writes:
...
But we are unnecessarily compiling the sub-regexes each time. Not that
this is probably a performance critical piece of code, but your "/o" is
doing very little, and this is exactly the sort perl wankery that I find
interesting.
Well, isn't the _sole_ point of using qr// to optimize by avoiding
recompilation?  If this is not a performance critical section of the code,
what is the point of this change?

This [PATCH 13/16] and also [PATCH 12/16] rewrite strings using qr// but
the patterns thus compiled are used exactly once before the control leaves
the scope of the variables, so...

It is a different story if the patch instead introduced module-level
global variables to hold a pre-compiled regexp objects, but that is not
what we are seeing here.

Re: [PATCH 13/16] send-email: extract_valid_address use qr// regexes and /o

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2016-06-15 22:49:40

On Thu, Sep 30, 2010 at 17:25, Junio C Hamano [off-list ref] wrote:
Jeff King [off-list ref] writes:
quoted
...
But we are unnecessarily compiling the sub-regexes each time. Not that
this is probably a performance critical piece of code, but your "/o" is
doing very little, and this is exactly the sort perl wankery that I find
interesting.
Well, isn't the _sole_ point of using qr// to optimize by avoiding
recompilation?  If this is not a performance critical section of the code,
what is the point of this change?

This [PATCH 13/16] and also [PATCH 12/16] rewrite strings using qr// but
the patterns thus compiled are used exactly once before the control leaves
the scope of the variables, so...
The point is to use Perl's data-types for what they're supposed to be
used for. In perl you *can* write:

    my $two = "1" + "1";

To get 2, but that's silly. You should just use integers instead of
string coercion:

    my $two = 1 + 1;

Similarly you *can* put regexes in strings, but perl has a first-class
datatype for it, so you should do:

    my $rx = qr/foo/;

Not:

    my $rx = "foo";

So it's just a change to use a better style. There are some tangible
advantages to using qr// over qq// (also known as ""), e.g. Emacs and
Vim will know to highlight the string as a regexp, and when the $rx is
interpolated Perl won't need to recompile it because it can just add a
pointer to the existing regex in the new pattern.

But the main reason here is to not write code that looks like it
targets Perl 5.5, but 5.8.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help