On Fri, Jul 28, 2017 at 10:09:09AM -0700, Father Chrysostomos via RT wrote: > On Fri, 28 Jul 2017 04:35:26 -0700, davem wrote: > > On Thu, Jul 27, 2017 at 04:22:47PM -0700, Father Chrysostomos via RT wrote: > > > On Thu, 27 Jul 2017 16:14:18 -0700, sprout wrote: > > > > On Thu, 27 Jul 2017 03:50:56 -0700, davem wrote: > > > > > A downside of &PL_sv_zero is that if assigned to a variable, that > > > > > variable > > > > > gets int, num and string values rather than just an int value. > > > > > > > > Why does that need to be the case? Why cannot PL_sv_zero have just > > > > the SvIOK flag on? > > > > because the first time you do, e.g. > > > > @a=(); > > say "size=" . @a; > > > > PL_sv_zero gets upgraded to an SvPOK() PVIV anyway. > > > > > > Does it matter that \(%h && $foo) now returns a reference to a read- > > > > only value when %h is empty? (If so, that can be solved by turning on > > > > PADTMP on PL_sv_zero.) > > > > > > I think it does matter. grep(1,@list_with_one_item) returning a mutable > > > 1 and grep(1,@list_with_zero_items) returning a read-only variable is > > > the kind of icky inconsistency that I tried hard to eliminate. > > > > Won't setting PADTMP cause PL_sv_zero's PVX buffer to be stolen? Or is > > that not done on a R/O var? > > It is not done on a R/O var. Now done. commit 02960b52b40b494fa4f6e1be81db5f3459ab91a9 Author: David Mitchell <davem@iabyn.com> AuthorDate: Fri Aug 4 15:17:44 2017 +0100 Commit: David Mitchell <davem@iabyn.com> CommitDate: Fri Aug 4 15:17:44 2017 +0100 set SVs_PADTMP flag on PL_sv_zero Where an op in scalar but not boolean context returns &PL_sv_zero as a more efficient way of doing sv_2mortal(newSViv(0)), the returned value must be mutable. For example my @a = (); my $r = \ scalar grep $_ == 1, @a; $$r += 10; By setting the SVs_PADTMP flag, this forces pp_srefgen() and similar to make a mortal copy of &PL_sv_zero. This kind of defeats the original optimisation, but the copy only kicks in under certain circumstances, whereas the newSViv(0) approach would create a new mortal every time. See RT #78288 for where FC suggested the problem and the solution. -- Diplomacy is telling someone to go to hell in such a way that they'll look forward to the tripThread Previous | Thread Next