git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 30, 2010, 18:56 UTC
Message-ID
<AANLkTin_b6eSnHgY2YCOfN7E83gEzrOpktUD3heOnfQw@mail.gmail.com>
In-Reply-To
<7vocbfjg7x.fsf@alter.siamese.dyndns.org>
On Thu, Sep 30, 2010 at 17:25, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> Jeff King <peff@peff.net> 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...

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.

Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 19 of 29 in “git-send-email cleanups”
  1. 00/16 git-send-email cleanupsÆvar Arnfjörð Bjarmason, Sep 30, 2010
  2. 01/16 send-email: use lexical filehandle for opendirÆvar Arnfjörð Bjarmason, Sep 30, 2010
  3. 02/16 send-email: use lexical filehandles for $composeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  4. 03/16 send-email: use lexical filehandles during sendingÆvar Arnfjörð Bjarmason, Sep 30, 2010
  5. 04/16 send-email: get_patch_subject doesn't need a prototypeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  6. 05/16 send-email: file_declares_8bit_cte doesn't need a prototypeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  7. 06/16 send-email: unique_email_list doesn't need a prototypeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  8. 07/16 send-email: cleanup_compose_files doesn't need a prototypeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  9. 08/16 send-email: use \E***\Q instead of \*\*\*Ævar Arnfjörð Bjarmason, Sep 30, 2010
  10. 09/16 send-email: sanitize_address use $foo, not "$foo"Ævar Arnfjörð Bjarmason, Sep 30, 2010
  11. 10/16 send-email: sanitize_address use qq["foo"], not "\"foo\""Ævar Arnfjörð Bjarmason, Sep 30, 2010
  12. 11/16 send-email: use (?:) instead of () if no match variables are neededÆvar Arnfjörð Bjarmason, Sep 30, 2010
  13. 12/16 send-email: is_rfc2047_quoted use qr// regexesÆvar Arnfjörð Bjarmason, Sep 30, 2010
  14. 13/16 send-email: extract_valid_address use qr// regexes and /oÆvar Arnfjörð Bjarmason, Sep 30, 2010
  15. Jeff KingSep 30, 2010
  16. Ævar Arnfjörð BjarmasonSep 30, 2010
  17. Jeff KingOct 1, 2010
  18. Junio C HamanoSep 30, 2010
  19. Ævar Arnfjörð BjarmasonSep 30, 2010
  20. 13/16 send-email: extract_valid_address use qr// regexesÆvar Arnfjörð Bjarmason, Sep 30, 2010
  21. 14/16 send-email: send_message die on $!, not $?Ævar Arnfjörð Bjarmason, Sep 30, 2010
  22. 15/16 send-email: make_message_id use "require" instead of "use"Ævar Arnfjörð Bjarmason, Sep 30, 2010
  23. 16/16 send-email: use Perl idioms in while loopÆvar Arnfjörð Bjarmason, Sep 30, 2010
  24. Brian GernhardtSep 30, 2010
  25. Jeff KingSep 30, 2010
  26. Brian GernhardtSep 30, 2010
  27. Ævar Arnfjörð BjarmasonSep 30, 2010
  28. Jay SoffianSep 30, 2010
  29. Jeff KingSep 30, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.