This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
refactor pp_tied
authorDaniel Dragan <bulk88@hotmail.com>
Tue, 27 May 2014 21:14:20 +0000 (17:14 -0400)
committerTony Cook <tony@develop-help.com>
Wed, 4 Jun 2014 00:50:40 +0000 (10:50 +1000)
remove some redundant code regarding stack handling

-removed:
  -4/-8 pop on SP
  +4/+8 push on SP
  PUTBACK

function's machine code size dropped from 0xC5 to 0xBD bytes on VC2003

pp_sys.c

index b445ee2..41a315d 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1005,21 +1005,23 @@ PP(pp_tied)
     dVAR;
     dSP;
     const MAGIC *mg;
     dVAR;
     dSP;
     const MAGIC *mg;
-    SV *sv = POPs;
+    dTOPss;
     const char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
                ? PERL_MAGIC_tied : PERL_MAGIC_tiedscalar;
 
     if (isGV_with_GP(sv) && !SvFAKE(sv) && !(sv = MUTABLE_SV(GvIOp(sv))))
     const char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
                ? PERL_MAGIC_tied : PERL_MAGIC_tiedscalar;
 
     if (isGV_with_GP(sv) && !SvFAKE(sv) && !(sv = MUTABLE_SV(GvIOp(sv))))
-       RETPUSHUNDEF;
+       goto ret_undef;
 
     if (SvTYPE(sv) == SVt_PVLV && LvTYPE(sv) == 'y' &&
 
     if (SvTYPE(sv) == SVt_PVLV && LvTYPE(sv) == 'y' &&
-       !(sv = defelem_target(sv, NULL))) RETPUSHUNDEF;
+       !(sv = defelem_target(sv, NULL))) goto ret_undef;
 
     if ((mg = SvTIED_mg(sv, how))) {
 
     if ((mg = SvTIED_mg(sv, how))) {
-       PUSHs(SvTIED_obj(sv, mg));
-       RETURN;
+       SETs(SvTIED_obj(sv, mg));
+       return NORMAL; /* PUTBACK not needed, pp_tied never moves SP */
     }
     }
-    RETPUSHUNDEF;
+    ret_undef:
+    SETs(&PL_sv_undef);
+    return NORMAL;
 }
 
 PP(pp_dbmopen)
 }
 
 PP(pp_dbmopen)