don't repeatedly call HvUSEDKEYS
authorDaniel Dragan <bulk88@hotmail.com>
Mon, 10 Mar 2014 12:29:56 +0000 (12:29 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 10 Mar 2014 12:29:56 +0000 (12:29 +0000)
HvUSEDKEYS contains a function call nowadays. Don't call it repeatedly.

dump.c
hv.c

diff --git a/dump.c b/dump.c
index b5998f9..354cd57 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -1882,20 +1882,22 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
            }
        }
        break;
-    case SVt_PVHV:
+    case SVt_PVHV: {
+       U32 usedkeys;
         if (SvOOK(sv)) {
             struct xpvhv_aux *const aux = HvAUX(sv);
             Perl_dump_indent(aTHX_ level, file, "  AUX_FLAGS = %"UVuf"\n",
                              (UV)aux->xhv_aux_flags);
         }
        Perl_dump_indent(aTHX_ level, file, "  ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
-       if (HvARRAY(sv) && HvUSEDKEYS(sv)) {
+       usedkeys = HvUSEDKEYS(sv);
+       if (HvARRAY(sv) && usedkeys) {
            /* Show distribution of HEs in the ARRAY */
            int freq[200];
 #define FREQ_MAX ((int)(sizeof freq / sizeof freq[0] - 1))
            int i;
            int max = 0;
-           U32 pow2 = 2, keys = HvUSEDKEYS(sv);
+           U32 pow2 = 2, keys = usedkeys;
            NV theoret, sum = 0;
 
            PerlIO_printf(file, "  (");
@@ -1937,13 +1939,13 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
             }
            while ((keys = keys >> 1))
                pow2 = pow2 << 1;
-           theoret = HvUSEDKEYS(sv);
+           theoret = usedkeys;
            theoret += theoret * (theoret-1)/pow2;
            PerlIO_putc(file, '\n');
            Perl_dump_indent(aTHX_ level, file, "  hash quality = %.1"NVff"%%", theoret/sum*100);
        }
        PerlIO_putc(file, '\n');
-       Perl_dump_indent(aTHX_ level, file, "  KEYS = %"IVdf"\n", (IV)HvUSEDKEYS(sv));
+       Perl_dump_indent(aTHX_ level, file, "  KEYS = %"IVdf"\n", (IV)usedkeys);
         {
             STRLEN count = 0;
             HE **ents = HvARRAY(sv);
@@ -2116,6 +2118,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
            }
        }
        break;
+    } /* case SVt_PVHV */
 
     case SVt_PVCV:
        if (CvAUTOLOAD(sv)) {
diff --git a/hv.c b/hv.c
index 91d4c39..9d80659 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -1625,8 +1625,10 @@ S_clear_placeholders(pTHX_ HV *hv, U32 items)
 
                if (--items == 0) {
                    /* Finished.  */
-                   HvTOTALKEYS(hv) -= (IV)HvPLACEHOLDERS_get(hv);
-                   if (HvUSEDKEYS(hv) == 0)
+                   I32 placeholders = HvPLACEHOLDERS_get(hv);
+                   HvTOTALKEYS(hv) -= (IV)placeholders;
+                   /* HvUSEDKEYS expanded */
+                   if ((HvTOTALKEYS(hv) - placeholders) == 0)
                        HvHASKFLAGS_off(hv);
                    HvPLACEHOLDERS_set(hv, 0);
                    return;