diff options
author | David Mitchell <davem@iabyn.com> | 2022-07-17 14:22:25 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-02-28 20:53:51 +0800 |
commit | 7460e4ea20e79a71632e499d2af24ad90ee1c58e (patch) | |
tree | 0710fecfbc8c95141cc1b2c130a44525790cae0c /pp_hot.c | |
parent | 0b6c6e4e306c6b4830a1cc197230ebdbb1c92140 (diff) | |
download | perl-7460e4ea20e79a71632e499d2af24ad90ee1c58e.tar.gz |
simplify scope-exit empty scalar context
Perl_leave_adjust_stacks(), which is called by all the scope-exiting ops
(pp_leave, pp_leavesub etc), handles scalar context by updating the list
of SVs on the stack to be returned to be just the one-item list at the
top of the stack (all other items on the stack being discarded).
For the special case of scalar context and no items on the return list,
it instead puts &PL_sv_undef at the lowest point on the stack and skips
most of the rest of the function. The rest of the function includes
things like shuffling down any args to be returned, which obliterates
any other stuff on that stack that needs discarding. For example in
for (qw(a b c)) { ....; return qw(x y z); ... }
the stack contains a b c x y z; the a,b,c need discarding and the x,y,z
shifting down.
This commit removes the 'skip rest' special behaviour, and makes scalar
return of an empty list behave the same as a scalar return of a
non-empty list. So it pushes &PL_sv_undef at the top of the stack,
then goes through the normal "shift and copy the top arg down the stack"
code path.
This is slightly less efficient, but this is relatively rare condition,
and will make converting Perl_leave_adjust_stacks() to handle a
reference-counted stack easier.
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -4913,13 +4913,9 @@ Perl_leave_adjust_stacks(pTHX_ SV **from_sp, SV **to_sp, U8 gimme, int pass) assert(from_sp == SP); EXTEND(SP, 1); *++SP = &PL_sv_undef; - to_sp = SP; - nargs = 0; - } - else { - from_sp = SP; - nargs = 1; } + from_sp = SP; + nargs = 1; } /* common code for G_SCALAR and G_LIST */ |