This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
‘Nonelems’ for pushing sparse array on the stack
authorFather Chrysostomos <sprout@cpan.org>
Mon, 22 Jan 2018 05:55:00 +0000 (21:55 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 19 Feb 2018 00:25:42 +0000 (16:25 -0800)
commit1f1dcfb516e063c29a4b9823ad97b1fc58ffc930
tree7f3616e6e28e78d9e1549eeca675453b6cbfedf7
parent6de18f4499a45f0d6876f2aca180b8a9f06e9240
‘Nonelems’ for pushing sparse array on the stack

To avoid having to create deferred elements every time a sparse array
is pushed on to the stack, store a magic scalar in the array itself,
which av_exists and refto recognise as not existing.

This means there is only a one-time cost for putting such arrays on
the stack.

It also means that deferred elements that live long enough don’t
start pointing to the wrong array entry if the array gets shifted (or
unshifted/spliced) in the mean time.  Instead, the scalar is already
in the array, so it cannot lose its place.  This fix only applies
when the array as a whole is pushed on to the stack, but it could be
extended in future commits to apply to other places where we currently
use deferred elements.
12 files changed:
av.c
embed.fnc
embed.h
mg.c
mg_names.inc
mg_raw.h
mg_vtable.h
pod/perlguts.pod
pp.c
pp_hot.c
proto.h
regen/mg_vtable.pl