This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_hv_pushkv(): unroll hv_iterkeysv()
authorDavid Mitchell <davem@iabyn.com>
Wed, 19 Jul 2017 08:11:33 +0000 (09:11 +0100)
committerDavid Mitchell <davem@iabyn.com>
Thu, 27 Jul 2017 10:30:24 +0000 (11:30 +0100)
Do our own mortal stack extending and handling.

hv.c

diff --git a/hv.c b/hv.c
index 37518c4..96228b3 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -995,14 +995,20 @@ Perl_hv_pushkv(pTHX_ HV *hv)
         }
     }
     else {
-        SSize_t extend_size;
-        /* 2*HvUSEDKEYS() should never be big enough to truncate or wrap */
-        assert(HvUSEDKEYS(hv) <= (SSize_t_MAX >> 1));
-        extend_size = (SSize_t)HvUSEDKEYS(hv) * 2;
-        EXTEND(SP, extend_size);
+        Size_t nkeys = HvUSEDKEYS(hv);
+        SSize_t nkv;
+        /* 2*nkeys() should never be big enough to truncate or wrap */
+        assert(nkeys <= (SSize_t_MAX >> 1));
+        nkv = nkeys * 2;
+
+        EXTEND_MORTAL(nkeys);
+        EXTEND(SP, nkv);
 
         while ((entry = hv_iternext(hv))) {
-            PUSHs(hv_iterkeysv(entry));
+            SV *keysv = newSVhek(HeKEY_hek(entry));
+            SvTEMP_on(keysv);
+            PL_tmps_stack[++PL_tmps_ix] = keysv;
+            PUSHs(keysv);
             PUSHs(HeVAL(entry));
         }
     }