develooper Front page | perl.perl5.porters | Postings from December 2017

Re: [perl #132588] In-place sort does not kill weak refs

Thread Previous
From:
Dave Mitchell
Date:
December 18, 2017 09:58
Subject:
Re: [perl #132588] In-place sort does not kill weak refs
Message ID:
20171218095800.GE3108@iabyn.com
On Fri, Dec 15, 2017 at 10:41:31PM +0000, Zefram wrote:
> Father Chrysostomos wrote:
> >$ perl5.27.7 -le 'use Scalar::Util "weaken"; weaken ($a = \$_[0]); @_ = sort @_; print $a; print \$_[0]'
> 
> After coming up with blessedness and then tiedness, I was wondering what
> other kinds of magic might be applied to an array element, and how sort
> would need to treat them.  This one confirms that in general sort needs
> to take the slow path for any kind of magic.  We don't distinguish between
> magic that's part of the container and magic that's part of the value, but
> we have little of the latter, so wouldn't lose much by not catering to it.


I think that by default, in-place sort should make a copy of every SV
(thus emulating the action of pp_aassign) *except* for special cases
of SV such as SvREFCNT == 1, no magic etc.

-- 
I don't want to achieve immortality through my work...
I want to achieve it through not dying.
    -- Woody Allen

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