This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Clean: Actually use HvUSEDKEYS() instead of HvKEYS()
authorMichael Witten <mfwitten@gmail.com>
Mon, 14 Mar 2011 06:57:43 +0000 (06:57 +0000)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 18 May 2011 23:35:16 +0000 (16:35 -0700)
This:

  commit 8aacddc1ea3837f8f1a911d90c644451fc7cfc86
  Author: Nick Ing-Simmons <nik@tiuk.ti.com>
  Date:   Tue Dec 18 15:55:22 2001 +0000

      Tidied version of Jeffrey Friedl's <jfriedl@yahoo.com> restricted hashes
       - added delete of READONLY value inhibit & test for same
       - re-tabbed

      p4raw-id: //depot/perlio@13760

essentially deprecated HvKEYS() in favor of HvUSEDKEYS(); this is
explained in line 144 (now 313) of file `hv.h':

  /*
   * HvKEYS gets the number of keys that actually exist(), and is provided
   * for backwards compatibility with old XS code. The core uses HvUSEDKEYS
   * (keys, excluding placeholdes) and HvTOTALKEYS (including placeholders)
   */

This commit simply puts that into practice, and is equivalent to running
the following (at least with a35ef416833511da752c4b5b836b7a8915712aab
checked out):

  git grep -l HvKEYS | sed /hv.h/d | xargs sed -i s/HvKEYS/HvUSEDKEYS/

Notice that HvKEYS is currently just an alias for HvUSEDKEYS:

  $ git show a35ef416833511da752c4b5b836b7a8915712aab:hv.h | sed -n 318p
  #define HvKEYS(hv) HvUSEDKEYS(hv)

According to `make tests':

  All tests successful.

dist/Storable/Storable.xs
dist/threads-shared/shared.xs
doop.c
dump.c
ext/B/B.xs
hv.c
mg.c
mro.c
pp.c
pp_hot.c
t/benchmark/rt26188-speed-up-keys-on-empty-hash.t

index 317ada7..e6d403b 100644 (file)
@@ -2289,7 +2289,7 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv)
 #ifdef HAS_RESTRICTED_HASHES
             HvTOTALKEYS(hv);
 #else
-            HvKEYS(hv);
+            HvUSEDKEYS(hv);
 #endif
        I32 i;
        int ret = 0;
index 7f1cd06..13e4a56 100644 (file)
@@ -1039,7 +1039,7 @@ sharedsv_array_mg_FETCHSIZE(pTHX_ SV *sv, MAGIC *mg)
         val = av_len((AV*) ssv);
     } else {
         /* Not actually defined by tie API but ... */
-        val = HvKEYS((HV*) ssv);
+        val = HvUSEDKEYS((HV*) ssv);
     }
     SHARED_RELEASE;
     return (val);
diff --git a/doop.c b/doop.c
index 4e0d9e3..c11555f 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -1262,7 +1262,7 @@ Perl_do_kv(pTHX)
            dTARGET;
 
            if (! SvTIED_mg((const SV *)keys, PERL_MAGIC_tied) ) {
-               i = HvKEYS(keys);
+               i = HvUSEDKEYS(keys);
            }
            else {
                i = 0;
@@ -1273,7 +1273,7 @@ Perl_do_kv(pTHX)
        RETURN;
     }
 
-    EXTEND(SP, HvKEYS(keys) * (dokeys + dovalues));
+    EXTEND(SP, HvUSEDKEYS(keys) * (dokeys + dovalues));
 
     PUTBACK;   /* hv_iternext and hv_iterval might clobber stack_sp */
     while ((entry = hv_iternext(keys))) {
diff --git a/dump.c b/dump.c
index 4e98394..32e7596 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -1830,13 +1830,13 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        break;
     case SVt_PVHV:
        Perl_dump_indent(aTHX_ level, file, "  ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
-       if (HvARRAY(sv) && HvKEYS(sv)) {
+       if (HvARRAY(sv) && HvUSEDKEYS(sv)) {
            /* 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 = HvKEYS(sv);
+           U32 pow2 = 2, keys = HvUSEDKEYS(sv);
            NV theoret, sum = 0;
 
            PerlIO_printf(file, "  (");
@@ -1878,13 +1878,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 = HvKEYS(sv);
+           theoret = HvUSEDKEYS(sv);
            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)HvKEYS(sv));
+       Perl_dump_indent(aTHX_ level, file, "  KEYS = %"IVdf"\n", (IV)HvUSEDKEYS(sv));
        Perl_dump_indent(aTHX_ level, file, "  FILL = %"IVdf"\n", (IV)HvFILL(sv));
        Perl_dump_indent(aTHX_ level, file, "  MAX = %"IVdf"\n", (IV)HvMAX(sv));
        Perl_dump_indent(aTHX_ level, file, "  RITER = %"IVdf"\n", (IV)HvRITER_get(sv));
index c1071c5..627f851 100644 (file)
@@ -1959,12 +1959,12 @@ void
 HvARRAY(hv)
        B::HV   hv
     PPCODE:
-       if (HvKEYS(hv) > 0) {
+       if (HvUSEDKEYS(hv) > 0) {
            SV *sv;
            char *key;
            I32 len;
            (void)hv_iterinit(hv);
-           EXTEND(sp, HvKEYS(hv) * 2);
+           EXTEND(sp, HvUSEDKEYS(hv) * 2);
            while ((sv = hv_iternextsv(hv, &key, &len))) {
                mPUSHp(key, len);
                PUSHs(make_sv_object(aTHX_ sv));
diff --git a/hv.c b/hv.c
index 5e96013..390eba8 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -800,7 +800,7 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
        xhv->xhv_keys++; /* HvTOTALKEYS(hv)++ */
        if (!counter) {                         /* initial entry? */
        } else if (xhv->xhv_keys > xhv->xhv_max) {
-               /* Use only the old HvKEYS(hv) > HvMAX(hv) condition to limit
+               /* Use only the old HvUSEDKEYS(hv) > HvMAX(hv) condition to limit
                   bucket splits on a rehashed hash, as we're not going to
                   split it again, and if someone is lucky (evil) enough to
                   get all the keys in one list they could exhaust our memory
@@ -1623,7 +1623,7 @@ S_clear_placeholders(pTHX_ HV *hv, U32 items)
                if (--items == 0) {
                    /* Finished.  */
                    HvTOTALKEYS(hv) -= (IV)HvPLACEHOLDERS_get(hv);
-                   if (HvKEYS(hv) == 0)
+                   if (HvUSEDKEYS(hv) == 0)
                        HvHASKFLAGS_off(hv);
                    HvPLACEHOLDERS_set(hv, 0);
                    return;
@@ -2003,7 +2003,7 @@ S_hv_auxinit(HV *hv) {
 =for apidoc hv_iterinit
 
 Prepares a starting point to traverse a hash table.  Returns the number of
-keys in the hash (i.e. the same as C<HvKEYS(hv)>).  The return value is
+keys in the hash (i.e. the same as C<HvUSEDKEYS(hv)>).  The return value is
 currently only meaningful for hashes without tie magic.
 
 NOTE: Before version 5.004_65, C<hv_iterinit> used to return the number of
@@ -2817,7 +2817,7 @@ S_share_hek_flags(pTHX_ const char *str, I32 len, register U32 hash, int flags)
 
        xhv->xhv_keys++; /* HvTOTALKEYS(hv)++ */
        if (!next) {                    /* initial entry? */
-       } else if (xhv->xhv_keys > xhv->xhv_max /* HvKEYS(hv) > HvMAX(hv) */) {
+       } else if (xhv->xhv_keys > xhv->xhv_max /* HvUSEDKEYS(hv) > HvMAX(hv) */) {
                hsplit(PL_strtab);
        }
     }
diff --git a/mg.c b/mg.c
index d061c51..cfa3197 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -1732,7 +1732,7 @@ Perl_magic_getnkeys(pTHX_ SV *sv, MAGIC *mg)
     if (hv) {
          (void) hv_iterinit(hv);
          if (! SvTIED_mg((const SV *)hv, PERL_MAGIC_tied))
-            i = HvKEYS(hv);
+            i = HvUSEDKEYS(hv);
          else {
             while (hv_iternext(hv))
                 i++;
diff --git a/mro.c b/mro.c
index 30be935..1185417 100644 (file)
--- a/mro.c
+++ b/mro.c
@@ -666,7 +666,7 @@ S_mro_clean_isarev(pTHX_ HV * const isa, const char * const name,
             if(svp) {
                 HV * const isarev = (HV *)*svp;
                 (void)hv_delete(isarev, name, len, G_DISCARD);
-                if(!HvARRAY(isarev) || !HvKEYS(isarev))
+                if(!HvARRAY(isarev) || !HvUSEDKEYS(isarev))
                     (void)hv_delete(PL_isarev, key, klen, G_DISCARD);
             }
         }
diff --git a/pp.c b/pp.c
index d91faa4..0069fba 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -6339,7 +6339,7 @@ PP(pp_boolkeys)
         }          
     }
 
-    XPUSHs(boolSV(HvKEYS(hv) != 0));
+    XPUSHs(boolSV(HvUSEDKEYS(hv) != 0));
     RETURN;
 }
 
index f8a61cb..531a33e 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -999,7 +999,7 @@ PP(pp_aassign)
            || SvMAGICAL(sv)
            || ! (SvTYPE(sv) == SVt_PVAV || SvTYPE(sv) == SVt_PVHV)
            || (SvTYPE(sv) == SVt_PVAV && AvFILL((AV*)sv) != -1)
-           || (SvTYPE(sv) == SVt_PVHV && HvKEYS((HV*)sv) != 0)
+           || (SvTYPE(sv) == SVt_PVHV && HvUSEDKEYS((HV*)sv) != 0)
            )
     ) {
        EXTEND_MORTAL(lastrelem - firstrelem + 1);
index 155aa3f..4770382 100644 (file)
@@ -86,5 +86,5 @@ __END__
     /* quick bailout if the hash is empty anyway.
        I don't know if placeholders are included in the KEYS count, so a defensive check
     */
-    if (! HvKEYS(hv) && !(flags & HV_ITERNEXT_WANTPLACEHOLDERS) )
+    if (! HvUSEDKEYS(hv) && !(flags & HV_ITERNEXT_WANTPLACEHOLDERS) )
         return NULL;