re_intuit_start(): don't set ml_anch on BOL
authorDavid Mitchell <davem@iabyn.com>
Tue, 18 Mar 2014 15:26:00 +0000 (15:26 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 19 Mar 2014 18:25:54 +0000 (18:25 +0000)
commit8f10278a677a11d641ea4247a9d28b058d11c78a
treec966270bfb67793bbc11840dfa2d33c9647e9446
parent48414424a7e7693e51c809e8bb1ea9e55e5436c8
re_intuit_start(): don't set ml_anch on BOL

re_intuit_start() decided that a pattern was capable of being anchored
after *any* \n in the string for a //m pattern that contains a BOL
(rather than an MBOL). This can happen by embedding one regex in another
for example.

This is an incorrect assumption, and means that intuit() might try
against every \n position in the string rather than just trying at the
beginning. With this commit, the following code on my machine reduces in
execution time from 7000ms to 5ms:

    my $r = qr/^abcd/;
    my $s = "abcd-xyz\n" x 500_000;
    $s =~ /$r\d{1,2}xyz/m for 1..200;
regexec.c
t/re/pat.t