Skip to content

Commit 6cbecd6

Browse files
committed
Move pp_entersub DIE() code into S_croak_undefined_subroutine
In `pp_entersub`, when trying to find the subroutine `CV` to execute, there are three nearby code paths that can result in a `DIE()`. This commit extracts the DIE() logic to a helper subroutine, `S_croak_undefined_subroutine`. This is partly in anticipation of additional warning logic, but also generally reduces the size of this hot function.
1 parent 3ed3768 commit 6cbecd6

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

pp_hot.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6212,6 +6212,26 @@ Perl_clear_defarray(pTHX_ AV* av, bool abandon)
62126212
}
62136213
}
62146214

6215+
/* S_croak_undefined_subroutine is a helper function for pp_entersub.
6216+
* It takes assorted DIE() logic out of that hot function.
6217+
*/
6218+
static void
6219+
S_croak_undefined_subroutine(pTHX_ CV const *cv, GV const *gv)
6220+
{
6221+
if (cv) {
6222+
if (CvLEXICAL(cv) && CvHASGV(cv))
6223+
croak("Undefined subroutine &%" SVf " called",
6224+
SVfARG(cv_name((CV*)cv, NULL, 0)));
6225+
else /* pp_entersub triggers when (CvANON(cv) || !CvHASGV(cv)) */
6226+
croak("Undefined subroutine called");
6227+
} else { /* pp_entersub triggers when (!cv) after `try_autoload` */
6228+
SV *sub_name = newSV_type_mortal(SVt_PV);
6229+
gv_efullname3(sub_name, gv, NULL);
6230+
6231+
croak("Undefined subroutine &%" SVf " called", SVfARG(sub_name));
6232+
}
6233+
NOT_REACHED; /* NOTREACHED */
6234+
}
62156235

62166236
PP(pp_entersub)
62176237
{
@@ -6306,15 +6326,12 @@ PP(pp_entersub)
63066326
assert((void*)&CvROOT(cv) == (void*)&CvXSUB(cv));
63076327
while (UNLIKELY(!CvROOT(cv))) {
63086328
GV* autogv;
6309-
SV* sub_name;
63106329

63116330
/* anonymous or undef'd function leaves us no recourse */
63126331
if (CvLEXICAL(cv) && CvHASGV(cv))
6313-
DIE(aTHX_ "Undefined subroutine &%" SVf " called",
6314-
SVfARG(cv_name(cv, NULL, 0)));
6315-
if (CvANON(cv) || !CvHASGV(cv)) {
6316-
DIE(aTHX_ "Undefined subroutine called");
6317-
}
6332+
S_croak_undefined_subroutine(aTHX_ cv, NULL);
6333+
if (CvANON(cv) || !CvHASGV(cv))
6334+
S_croak_undefined_subroutine(aTHX_ cv, NULL);
63186335

63196336
/* autoloaded stub? */
63206337
if (cv != GvCV(gv = CvGV(cv))) {
@@ -6330,11 +6347,8 @@ PP(pp_entersub)
63306347
: 0));
63316348
cv = autogv ? GvCV(autogv) : NULL;
63326349
}
6333-
if (!cv) {
6334-
sub_name = sv_newmortal();
6335-
gv_efullname3(sub_name, gv, NULL);
6336-
DIE(aTHX_ "Undefined subroutine &%" SVf " called", SVfARG(sub_name));
6337-
}
6350+
if (!cv)
6351+
S_croak_undefined_subroutine(aTHX_ NULL, gv);
63386352
}
63396353

63406354
/* unrolled "CvCLONE(cv) && ! CvCLONED(cv)" */

0 commit comments

Comments
 (0)