This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
S_padhv_rv2hv_common(): unroll hv_scalar() calls
authorDavid Mitchell <davem@iabyn.com>
Wed, 19 Jul 2017 16:06:28 +0000 (17:06 +0100)
committerDavid Mitchell <davem@iabyn.com>
Thu, 27 Jul 2017 10:30:24 +0000 (11:30 +0100)
This function makes a couple of calls to hv_scalar(), which does
one of two things depending on whether hash is tied or not.
Since in S_padhv_rv2hv_common() we've already determined whether the
hash is tied, just include the relevant part(s) of hv_scalar() directly.

The code will be reorganised shortly.

pp_hot.c

index a44ee34..233d4d4 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -974,6 +974,7 @@ PERL_STATIC_INLINE OP*
 S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gimme, bool is_keys, bool has_targ)
 {
     bool tied;
 S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gimme, bool is_keys, bool has_targ)
 {
     bool tied;
+    MAGIC *mg;
     dSP;
 
     assert(PL_op->op_type == OP_PADHV || PL_op->op_type == OP_RV2HV);
     dSP;
 
     assert(PL_op->op_type == OP_PADHV || PL_op->op_type == OP_RV2HV);
@@ -987,7 +988,7 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gimme, bool is_keys, bool has_targ)
         /* 'keys %h' masquerading as '%h': reset iterator */
         (void)hv_iterinit(hv);
 
         /* 'keys %h' masquerading as '%h': reset iterator */
         (void)hv_iterinit(hv);
 
-    tied = SvRMAGICAL(hv) && mg_find(MUTABLE_SV(hv), PERL_MAGIC_tied);
+    tied = SvRMAGICAL(hv) && (mg = mg_find(MUTABLE_SV(hv), PERL_MAGIC_tied));
 
     if (  (  PL_op->op_private & OPpTRUEBOOL
          || (  PL_op->op_private & OPpMAYBE_TRUEBOOL
 
     if (  (  PL_op->op_private & OPpTRUEBOOL
          || (  PL_op->op_private & OPpMAYBE_TRUEBOOL
@@ -995,7 +996,7 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gimme, bool is_keys, bool has_targ)
           )
     ) {
         if (tied)
           )
     ) {
         if (tied)
-            PUSHs(Perl_hv_scalar(aTHX_ hv));
+            PUSHs(magic_scalarpack(hv, mg));
         else
             PUSHs(HvUSEDKEYS(hv) ? &PL_sv_yes : &PL_sv_zero);
     }
         else
             PUSHs(HvUSEDKEYS(hv) ? &PL_sv_yes : &PL_sv_zero);
     }
@@ -1016,8 +1017,12 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gimme, bool is_keys, bool has_targ)
             else
                 mPUSHi(i);
         }
             else
                 mPUSHi(i);
         }
-        else
-            PUSHs(Perl_hv_scalar(aTHX_ hv));
+        else {
+            if (tied)
+                PUSHs(magic_scalarpack(hv, mg));
+            else
+                mPUSHi(HvUSEDKEYS(hv));
+        }
     }
 
     PUTBACK;
     }
 
     PUTBACK;