stop $foo =~ /(bar)/g skipping copy
authorDavid Mitchell <davem@iabyn.com>
Fri, 24 Aug 2012 15:17:47 +0000 (16:17 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sat, 8 Sep 2012 14:42:07 +0000 (15:42 +0100)
commita41aa44d9dc4a3ba586d871754bd11137bdc37a2
treecf9777a88b54f956185fc04cf3b93adfe64692ef
parent9414be0160a1f343d4ae75ec161fec610da39c84
stop $foo =~ /(bar)/g skipping copy

Normally in the presence of captures, a successful regex execution
makes a copy of the matched string, so that $1 et al give the right
value even if the original string is changed; i.e.

    $foo =~ /(123)/g;
    $foo = "bar";
    is("$1", "123");

Until now that test would fail, because perl used to skip the copy for
the scalar /(...)/g case (but not the C<$&; //g> case). This was to
avoid a huge slowdown in code like the following:

    $x = 'x' x 1_000_000;
    1 while $x =~ /(.)/g;

which would otherwise end up copying a 1Mb string a million times.

Now that (with the last commit but one) we copy only the required
substring of the original string (a 1-byte substring in the above
example), we can remove this fast-but-incorrect hack.
pp_hot.c
t/re/pat_advanced.t
t/re/pat_psycho.t