This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Abolish xbm_rare. Move BmUSEFUL() to union _xnvu and BmPREVIOUS() to the UV.
authorNicholas Clark <nick@ccl4.org>
Tue, 17 May 2011 09:26:49 +0000 (10:26 +0100)
committerNicholas Clark <nick@ccl4.org>
Sat, 11 Jun 2011 07:40:02 +0000 (09:40 +0200)
This reduces the complexity of the union declarations in sv.h.

As B.xs is accessing the structures/unions directly, instead of using the
macros, it needs a patch too.

ext/B/B.xs
sv.h

index f4d5fea..1ca4fd8 100644 (file)
@@ -1370,8 +1370,13 @@ MODULE = B       PACKAGE = B::IV
 #define PVMG_stash_ix  sv_SVp | offsetof(struct xpvmg, xmg_stash)
 
 #if PERL_VERSION >= 10
+#  if PERL_VERSION > 14
+#    define PVBM_useful_ix     sv_I32p | offsetof(struct xpvgv, xnv_u.xbm_s.xbm_useful)
+#    define PVBM_previous_ix   sv_UVp | offsetof(struct xpvuv, xuv_uv)
+#  else
 #define PVBM_useful_ix sv_I32p | offsetof(struct xpvgv, xiv_u.xivu_i32)
 #define PVBM_previous_ix    sv_U32p | offsetof(struct xpvgv, xnv_u.xbm_s.xbm_previous)
+#  endif
 #define PVBM_rare_ix   sv_U8p | offsetof(struct xpvgv, xnv_u.xbm_s.xbm_rare)
 #else
 #define PVBM_useful_ix sv_I32p | offsetof(struct xpvbm, xbm_useful)
diff --git a/sv.h b/sv.h
index 04a45c2..c102985 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -419,8 +419,7 @@ union _xnvu {
        U32 xhigh;
     }      xpad_cop_seq;       /* used by pad.c for cop_sequence */
     struct {
-       U32 xbm_previous;       /* how many characters in string before rare? */
-       U8  xbm_flags;
+       I32 xbm_useful;
        U8  xbm_rare;           /* rarest character in string */
     }      xbm_s;              /* fields from PVBM */
 };
@@ -428,7 +427,6 @@ union _xnvu {
 union _xivu {
     IV     xivu_iv;            /* integer value */
     UV     xivu_uv;
-    I32            xivu_i32;           /* BmUSEFUL */
     HEK *   xivu_namehek;      /* xpvlv, xpvgv: GvNAME */
 };
 
@@ -1311,18 +1309,18 @@ the scalar's value cannot change unless written to.
            assert(SvTYPE(_bmuseful) == SVt_PVGV);                      \
            assert(SvVALID(_bmuseful));                                 \
            assert(!SvIOK(_bmuseful));                                  \
-           &(((XPVGV*) SvANY(_bmuseful))->xiv_u.xivu_i32);             \
+           &(((XPVGV*) SvANY(_bmuseful))->xnv_u.xbm_s.xbm_useful);     \
         }))
 #  define BmPREVIOUS(sv)                                               \
     (*({ SV *const _bmprevious = MUTABLE_SV(sv);                       \
                assert(SvTYPE(_bmprevious) == SVt_PVGV);                \
                assert(SvVALID(_bmprevious));                           \
-           &(((XPVGV*) SvANY(_bmprevious))->xnv_u.xbm_s.xbm_previous); \
+           &(((XPVGV*) SvANY(_bmprevious))->xiv_u.xivu_uv);            \
         }))
 #else
 #  define BmRARE(sv)           ((XPVGV*) SvANY(sv))->xnv_u.xbm_s.xbm_rare
-#  define BmUSEFUL(sv)         ((XPVGV*) SvANY(sv))->xiv_u.xivu_i32
-#  define BmPREVIOUS(sv)       ((XPVGV*) SvANY(sv))->xnv_u.xbm_s.xbm_previous
+#  define BmUSEFUL(sv)         ((XPVGV*) SvANY(sv))->xnv_u.xbm_s.xbm_useful
+#  define BmPREVIOUS(sv)       ((XPVGV*) SvANY(sv))->xiv_u.xivu_uv
 
 #endif