Skip to content

Commit

Permalink
pp_return: optimise a couple of conditions
Browse files Browse the repository at this point in the history
Change:

    if (cxix < 0) {
        A; return;
    }
    if (cxix < cxstack_ix)
        B;

to

    if (cxix < cxstack_ix) {
        if (cxix < 0) {
            A; return;
        }
        B;
    }

This is functionally the same, since cxstack_ix is always positive at
this point, and makes for a quicker code path (one less test and branch)
in the reasonably common case of a return from a sub which doesn't
have any extra nested contexts to pop.
  • Loading branch information
iabyn committed Jun 19, 2015
1 parent a375cec commit d40dc6b
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions pp_ctl.c
Expand Up @@ -2418,27 +2418,28 @@ PP(pp_return)
dSP; dMARK;
PERL_CONTEXT *cx;
SV **oldsp;

const I32 cxix = dopoptosub(cxstack_ix);

if (cxix < 0) {
if (CxMULTICALL(cxstack)) { /* In this case we must be in a
* sort block, which is a CXt_NULL
* not a CXt_SUB */
dounwind(0);
/* if we were in list context, we would have to splice out
* any junk before the return args, like we do in the general
* pp_return case, e.g.
* sub f { for (junk1, junk2) { return arg1, arg2 }}
*/
assert(cxstack[0].blk_gimme == G_SCALAR);
return 0;
}
else
DIE(aTHX_ "Can't return outside a subroutine");
}
if (cxix < cxstack_ix)
assert(cxstack_ix >= 0);
if (cxix < cxstack_ix) {
if (cxix < 0) {
if (CxMULTICALL(cxstack)) { /* In this case we must be in a
* sort block, which is a CXt_NULL
* not a CXt_SUB */
dounwind(0);
/* if we were in list context, we would have to splice out
* any junk before the return args, like we do in the general
* pp_return case, e.g.
* sub f { for (junk1, junk2) { return arg1, arg2 }}
*/
assert(cxstack[0].blk_gimme == G_SCALAR);
return 0;
}
else
DIE(aTHX_ "Can't return outside a subroutine");
}
dounwind(cxix);
}

cx = &cxstack[cxix];

Expand Down

0 comments on commit d40dc6b

Please sign in to comment.