add aux_flags field to HVs with aux struct
authorDavid Mitchell <davem@iabyn.com>
Sat, 15 Feb 2014 16:15:11 +0000 (16:15 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 28 Feb 2014 13:42:49 +0000 (13:42 +0000)
Add an extra U32 general flags field to the xpvhv_aux struct (which is
used on HVs such as stashes, that need extra fields).

On 64-bit systems, this doesn't consume any extra space since there's
already an odd number of I32/U32 fields. On 32-bit systems it will consume
an  extra 4 bytes. But of course only on those hashes that have the aux
struct.

As well as providing extra flags in the AUX case, it will also allow
us to free up at least one general flag bit for HVs - see next commit.

dump.c
ext/Devel-Peek/t/Peek.t
hv.c
hv.h
sv.c

diff --git a/dump.c b/dump.c
index 8c14b3b..b5998f9 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -1883,6 +1883,11 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        }
        break;
     case SVt_PVHV:
+        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)) {
            /* Show distribution of HEs in the ARRAY */
index 9fb1f01..2cfd8a5 100644 (file)
@@ -821,6 +821,7 @@ do_test('ENAME on a stash',
     FLAGS = \\(OOK,SHAREKEYS\\)
     IV = 1                                     # $] < 5.009
     NV = $FLOAT                                        # $] < 5.009
+    AUX_FLAGS = 0                               # $] > 5.019008
     ARRAY = $ADDR
     KEYS = 0
     FILL = 0 \(cached = 0\)
@@ -845,6 +846,7 @@ do_test('ENAMEs on a stash',
     FLAGS = \\(OOK,SHAREKEYS\\)
     IV = 1                                     # $] < 5.009
     NV = $FLOAT                                        # $] < 5.009
+    AUX_FLAGS = 0                               # $] > 5.019008
     ARRAY = $ADDR
     KEYS = 0
     FILL = 0 \(cached = 0\)
@@ -871,6 +873,7 @@ do_test('ENAMEs on a stash with no NAME',
     FLAGS = \\(OOK,OVERLOAD,SHAREKEYS\\)       # $] >=5.017
     IV = 1                                     # $] < 5.009
     NV = $FLOAT                                        # $] < 5.009
+    AUX_FLAGS = 0                               # $] > 5.019008
     ARRAY = $ADDR
     KEYS = 0
     FILL = 0 \(cached = 0\)
@@ -923,6 +926,7 @@ do_test('small hash after keys',
     FLAGS = \\(PADMY,OOK,SHAREKEYS\\)
     IV = 1                                     # $] < 5.009
     NV = $FLOAT                                        # $] < 5.009
+    AUX_FLAGS = 0                               # $] > 5.019008
     ARRAY = $ADDR  \\(0:[67],.*\\)
     hash quality = [0-9.]+%
     KEYS = 2
@@ -954,6 +958,7 @@ do_test('small hash after keys and scalar',
     FLAGS = \\(PADMY,OOK,SHAREKEYS\\)
     IV = 1                                     # $] < 5.009
     NV = $FLOAT                                        # $] < 5.009
+    AUX_FLAGS = 0                               # $] > 5.019008
     ARRAY = $ADDR  \\(0:[67],.*\\)
     hash quality = [0-9.]+%
     KEYS = 2
@@ -986,6 +991,7 @@ do_test('large hash',
     FLAGS = \\(PADMY,OOK,SHAREKEYS\\)
     IV = 1                                     # $] < 5.009
     NV = $FLOAT                                        # $] < 5.009
+    AUX_FLAGS = 0                               # $] > 5.019008
     ARRAY = $ADDR  \\(0:\d+,.*\\)
     hash quality = \d+\\.\d+%
     KEYS = 1000
diff --git a/hv.c b/hv.c
index a9322aa..a4624f0 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -1979,6 +1979,7 @@ S_hv_auxinit(pTHX_ HV *hv) {
     iter->xhv_name_count = 0;
     iter->xhv_backreferences = 0;
     iter->xhv_mro_meta = NULL;
+    iter->xhv_aux_flags = 0;
     return iter;
 }
 
diff --git a/hv.h b/hv.h
index 66edfc2..498e6f0 100644 (file)
--- a/hv.h
+++ b/hv.h
@@ -119,6 +119,7 @@ struct xpvhv_aux {
                                    used to detect each() after insert for warnings */
 #endif
     U32         xhv_fill_lazy;
+    U32         xhv_aux_flags;      /* assorted extra flags */
 };
 
 /* hash structure: */
diff --git a/sv.c b/sv.c
index a0e0cbe..a0e0c5f 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12615,6 +12615,7 @@ S_sv_dup_common(pTHX_ const SV *const sstr, CLONE_PARAMS *const param)
                        daux->xhv_name_count = saux->xhv_name_count;
 
                        daux->xhv_fill_lazy = saux->xhv_fill_lazy;
+                       daux->xhv_aux_flags = saux->xhv_aux_flags;
                        daux->xhv_riter = saux->xhv_riter;
                        daux->xhv_eiter = saux->xhv_eiter
                            ? he_dup(saux->xhv_eiter,