From: Chip Salzenberg Date: Sat, 3 Feb 1996 17:45:32 +0000 (-0500) Subject: Beta3: Combine code: provide_refs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=02a9e96851dcb81d50f6e6c61f7be3c108215ef5;p=p5sagit%2Fp5-mst-13.2.git Beta3: Combine code: provide_refs --- diff --git a/pp_hot.c b/pp_hot.c index 4b885d4..5988d2e 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -226,20 +226,8 @@ PP(pp_padsv) if (op->op_flags & OPf_MOD) { if (op->op_private & OPpLVAL_INTRO) SAVECLEARSV(curpad[op->op_targ]); - else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) { - SV* sv = curpad[op->op_targ]; - if (SvGMAGICAL(sv)) - mg_get(sv); - if (!SvOK(sv)) { - if (SvREADONLY(sv)) - croak(no_modify); - (void)SvUPGRADE(sv, SVt_RV); - SvRV(sv) = (op->op_private & OPpDEREF_HV ? - (SV*)newHV() : (SV*)newAV()); - SvROK_on(sv); - SvSETMAGIC(sv); - } - } + else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) + provide_ref(op, curpad[op->op_targ]); } RETURN; } @@ -1218,18 +1206,8 @@ PP(pp_helem) DIE(no_helem, key); if (op->op_private & OPpLVAL_INTRO) save_svref(svp); - else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) { - SV* sv = *svp; - if (SvGMAGICAL(sv)) - mg_get(sv); - if (!SvOK(sv)) { - (void)SvUPGRADE(sv, SVt_RV); - SvRV(sv) = (op->op_private & OPpDEREF_HV ? - (SV*)newHV() : (SV*)newAV()); - SvROK_on(sv); - SvSETMAGIC(sv); - } - } + else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) + provide_ref(op, *svp); } PUSHs(svp ? *svp : &sv_undef); RETURN; @@ -1898,23 +1876,31 @@ PP(pp_aelem) DIE(no_aelem, elem); if (op->op_private & OPpLVAL_INTRO) save_svref(svp); - else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) { - SV* sv = *svp; - if (SvGMAGICAL(sv)) - mg_get(sv); - if (!SvOK(sv)) { - (void)SvUPGRADE(sv, SVt_RV); - SvRV(sv) = (op->op_private & OPpDEREF_HV ? - (SV*)newHV() : (SV*)newAV()); - SvROK_on(sv); - SvSETMAGIC(sv); - } - } + else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) + provide_ref(op, *svp); } PUSHs(svp ? *svp : &sv_undef); RETURN; } +void +provide_ref(op, sv) +OP* op; +SV* sv; +{ + if (SvGMAGICAL(sv)) + mg_get(sv); + if (!SvOK(sv)) { + if (SvREADONLY(sv)) + croak(no_modify); + (void)SvUPGRADE(sv, SVt_RV); + SvRV(sv) = (op->op_private & OPpDEREF_HV ? + (SV*)newHV() : (SV*)newAV()); + SvROK_on(sv); + SvSETMAGIC(sv); + } +} + PP(pp_method) { dSP;