develooper Front page | perl.perl5.porters | Postings from November 2012

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

Thread Previous
From:
Father Chrysostomos via RT
Date:
November 25, 2012 14:15
Subject:
[perl #86042] (not) referencing $& causes match failure
Message ID:
rt-3.6.HEAD-17500-1353881714-1868.86042-15-0@perl.org
On Sun Mar 13 12:59:21 2011, demerphq wrote:
> On 13 March 2011 20:26, yves orton via RT <perlbug-followup@perl.org>
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.
> 
> And for the observant, this case is actually special cased to NOT copy
> the string even if capture buffers are used.

David Mitchell (git says it was David that time, not Dave) fixed this in
the branched merged to blead as 1703c1fc996f9.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=86042

Thread Previous


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