[MERGE] only copy bits of regex match string
When making a copy of the string being matched against (so that $1, $&
et al continue to show the correct value even if the original string is
subsequently modified), only copy that substring of the original string
needed for the capture variables, rather than copying the whole string.
This is a big win for code like
$&;
$_ = 'x' x 1_000_000;
1 while /(.)/;
Also, when pessimizing if the code contains $`, $& or $', record
the presence of each variable separately, so that the determination of the
substring range is based on each variable separately. So performance-wise,
$&; /x/
is now roughly equivalent to
/(x)/
whereas previously it was like
/^(.*)(x)(.*)$/
and
$&; $'; /x/
is now roughly equivalent to
/(x)(.*)$/
etc.
Finally, this code (when not in the presence of $& etc)
$_ = 'x' x 1_000_000;
1 while /(.)/;
used to skip the buffer copy for performance reasons, but suffered from $1
etc changing if the original string changed. That's now been fixed too.