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

Mutable constant-expression values

Thread Next
From:
Aristotle Pagaltzis
Date:
July 22, 2011 05:02
Subject:
Mutable constant-expression values
Message ID:
20110722120242.GA24810@klangraum.plasmasturm.org
Something just occurred to me. In another thread I had an
exchange with Chip, and we got to this point:

* Reverend Chip <rev.chip@gmail.com> in <4E1E6E83.7030606@gmail.com> [2011-07-14 06:25]:
> On 7/13/2011 5:35 PM, Aristotle Pagaltzis wrote:
> > If you write ++${\10} that should yield 11 no matter how
> > often you evaluate it. You should get a copy (or rather, via
> > CoW, a potential copy) when you evaluate a constant....
>
> I appreciate the purity & consistency of this position, but I'm
> not fond of it, because I foresee it costing a lot of
> performance for absolutely no practical gain. Its only payoff
> is ideological bragging rights, which don't motivate me.

But now that I think of it, not only does this need no CoW, it
should not even cost any performance at all (even without CoW!).
After all, throwing “Modification of a read-only value attempted”
already requires a check. The only thing that would have to be
done to implement the above change is to change most instances
of `Perl_croak_no_modify` to check for a real constant and make
a mutable copy of the value to operate on and return instead of
always throwing the error.

I.e. constants would be copied to a mutable SV at the point in
time at which someone attempts to mutate them. The impact (and
performance hit) on all other operations would be *zero*.

Am I missing anything here? Is that all? (Conceptually speaking.
The implementation would take some work.)

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

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