From aff26e98cc0d960141a257e961234949344b055b Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 9 Nov 2013 21:44:26 -0800 Subject: [PATCH] op.c: Factor out common entersub-building code This same incantation occurs four times, though the readpipe variant was slightly different. The only difference was the lack of a scalar flag on a null op, which makes no difference: - <1> ex-rv2cv sK ->- 5 <$> gv(*require) s ->6 - <1> ex-rv2cv K ->- 5 <$> gv(*readpipe) s ->6 So I did not include the scalar() call, as it was unnecessary. Also, I changed op_append_elem to newLISTOP, since the former calls the lat- ter anyway in these cases. --- op.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/op.c b/op.c index 82f6ee1..e9a356e 100644 --- a/op.c +++ b/op.c @@ -5506,6 +5506,15 @@ Perl_vload_module(pTHX_ U32 flags, SV *name, SV *ver, va_list *args) LEAVE; } +PERL_STATIC_INLINE OP * +S_new_entersubop(pTHX_ GV *gv, OP *arg) +{ + return newUNOP(OP_ENTERSUB, OPf_STACKED, + newLISTOP(OP_LIST, 0, arg, + newUNOP(OP_RV2CV, 0, + newGVOP(OP_GV, 0, gv)))); +} + OP * Perl_dofile(pTHX_ OP *term, I32 force_builtin) { @@ -5516,10 +5525,7 @@ Perl_dofile(pTHX_ OP *term, I32 force_builtin) PERL_ARGS_ASSERT_DOFILE; if (!force_builtin && (gv = gv_override("do", 2))) { - doop = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, term, - scalar(newUNOP(OP_RV2CV, 0, - newGVOP(OP_GV, 0, gv))))); + doop = S_new_entersubop(aTHX_ gv, term); } else { doop = newUNOP(OP_DOFILE, 0, scalar(term)); @@ -8493,11 +8499,7 @@ Perl_ck_backtick(pTHX_ OP *o) /* qx and `` have a null pushmark; CORE::readpipe has only one kid. */ if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_sibling && (gv = gv_override("readpipe",8))) { - newop = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, - cUNOPo->op_first->op_sibling, - newCVREF(0, newGVOP(OP_GV, 0, gv)) - )); + newop = S_new_entersubop(aTHX_ gv, cUNOPo->op_first->op_sibling); cUNOPo->op_first->op_sibling = NULL; } else if (!(o->op_flags & OPf_KIDS)) @@ -9301,11 +9303,7 @@ Perl_ck_glob(pTHX_ OP *o) */ o->op_flags |= OPf_SPECIAL; o->op_targ = pad_alloc(OP_GLOB, SVs_PADTMP); - o = newLISTOP(OP_LIST, 0, o, NULL); - o = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, o, - scalar(newUNOP(OP_RV2CV, 0, - newGVOP(OP_GV, 0, gv))))); + o = S_new_entersubop(aTHX_ gv, o); o = newUNOP(OP_NULL, 0, o); o->op_targ = OP_GLOB; /* hint at what it used to be: eg in newWHILEOP */ return o; @@ -9774,11 +9772,7 @@ Perl_ck_require(pTHX_ OP *o) #ifndef PERL_MAD op_free(o); #endif - newop = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, kid, - scalar(newUNOP(OP_RV2CV, 0, - newGVOP(OP_GV, 0, - gv))))); + newop = S_new_entersubop(aTHX_ gv, kid); op_getmad(o,newop,'O'); return newop; } -- 2.7.4