Enache Adrian <enache@rdslink.ro> wrote: :> The example could be rewritten: :> :> #! /usr/bin/perl :> $p=1; :> foreach (1,2,3,4) { :> $p++ if /(??{ $p })/; :> } :> print $p; :> __END__ :> :> this prints 2, not 5. : :My previous patch has the drawback of dropping the optimization even :in simple cases where $p is a regular variable, and it's just accessed, :not modified. : :The modified version works as follows: : - only a magic_setregexp() method is added to 'r'-magical variables, : method which calls sv_unmagic(sv,'r'), forcing recompilation if : the variable is set. : - if the variable has some 'get' magic methods, it isn't made : 'r'-magical in the first place (regexec.c ~ 2900) : - if the variable gets some 'get' magic methods since it was cached, : (ex. it is tied) its 'r' magic is dropped (regexec.c ~2876) : :I added 2 two tests to op/pat.t, too. Thanks, applied as #18782. HugoThread Previous | Thread Next