develooper Front page | perl.perl5.porters | Postings from August 2011

[perl #86042] (not) referencing $& causes match failure

Thread Next
From:
Father Chrysostomos via RT
Date:
August 26, 2011 23:32
Subject:
[perl #86042] (not) referencing $& causes match failure
Message ID:
rt-3.6.HEAD-31297-1314426751-1685.86042-15-0@perl.org
On Mon Mar 14 05:01:20 2011, demerphq wrote:
> On 13 March 2011 22:47, Father Chrysostomos via RT
> <perlbug-followup@perl.org> wrote:
> > On Sun Mar 13 12:26:26 2011, demerphq wrote:
> >> I fixed this once, and then we had to rip it out because the
> performance
> >> implications were dire.
> >>
> >> Mentioning $` $& $' *anywhere* will "fix" the bug, because they
> cause
> >> all strings to be copied before matches (to avoid the same "bug"
> this
> >> code triggers).
> >>
> >> However this also causes the slowdown we wanted to avoid by not
> fixing it.
> >>
> >> The problem is code like this:
> >>
> >> my $str="something really big";
> >> while ($str=~/(\w+)/g) {
> >>
> >> }
> >>
> >> With the fix I did, and with $& mentioned the above will copy $str
> each
> >> time through, and thus when $str is 1GB will become punishingly
> slow.
> >>
> >> I don't think this has an easy fix.
> >
> > How about some variation of COW? (I.e., a post- (as opposed to pre-)
> > match copy when the target is assigned to.)
> 
> If its doable maybe. But i have a feeling its a can of worms.

Can someone point me to the code that does the pre-match copy and the
code that sets up $1, $2, etc.?


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