develooper Front page | perl.perl5.porters | Postings from March 2014

Re: [perl #121484] /m causing false negative

Thread Previous | Thread Next
From:
Tom Hukins
Date:
March 21, 2014 14:16
Subject:
Re: [perl #121484] /m causing false negative
Message ID:
20140321141621.GA10295@eborcom.com
On Fri, Mar 21, 2014 at 06:01:01AM -0700, Zefram wrote:
> $ perl5.19.10 -lwe 'print "wibble" =~ /\Awibble\z/m ? "yes" : "no"'
> no
> $ perl5.19.9 -lwe 'print "wibble" =~ /\Awibble\z/m ? "yes" : "no"'
> yes
 
I've just bisected this to the following plausible-looking commit:

d0d4464849e2b30aee89c175ccb5465795de10ce is the first bad commit
commit d0d4464849e2b30aee89c175ccb5465795de10ce
Author: David Mitchell <davem@iabyn.com>
Date:   Tue Mar 18 20:15:27 2014 +0000

    re_intuit_start(): reduce scope of /^...$/m test
    
    Intuit has a quick reject test for a fixed pattern that is anchored at
    both ends. For example, with the pattern /^abcd$/, only the exact strings
    "abcd" or "abcd\n" will match; anything else, and the match immediately
    fails.
    
    A fix for [perl #115242] correctly made intuit skip the test in the
    presence of //m, since in this case the $ doesn't necessarily correspond
    to the end of the string.
    
    However, the fix was too wide in scope; it caused //m patterns to skip
    searching for a known string anchored just at the start, as well as one
    anchored at both ends.
    
    With this commit, the following code now runs in a few milliseconds rather
    than a few seconds on my machine:
    
        $s = "abcdefg" x 1_000_000;
        $s =~ /(?-m:^)abcX?fg/m for 1..100;

Tom

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About