S_del_body is sufficiently small that inlining it is a space win.
[p5sagit/p5-mst-13.2.git] / sv.c
diff --git a/sv.c b/sv.c
index 44b5b34..13e3f12 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -1118,14 +1118,13 @@ S_new_body(pTHX_ void **arena_root, void **root, size_t size)
 
 /* return a thing to the free list */
 
-STATIC void
-S_del_body(pTHX_ void *thing, void **root)
-{
-    LOCK_SV_MUTEX;
-    *(void **)thing = *root;
-    *root = (void*)thing;
-    UNLOCK_SV_MUTEX;
-}
+#define del_body(thing, root)                  \
+    STMT_START {                               \
+       LOCK_SV_MUTEX;                          \
+       *(void **)thing = *root;                \
+       *root = (void*)thing;                   \
+       UNLOCK_SV_MUTEX;                        \
+    } STMT_END
 
 /* Conventionally we simply malloc() a big block of memory, then divide it
    up into lots of the thing that we're allocating.
@@ -1142,8 +1141,8 @@ S_del_body(pTHX_ void *thing, void **root)
                 (void**)&PL_ ## lctype ## _root,                       \
                 sizeof(TYPE))
 
-#define del_body(p,TYPE,lctype)                                                \
-    S_del_body(aTHX_ (void*)p, (void**)&PL_ ## lctype ## _root)
+#define del_body_type(p,TYPE,lctype)                   \
+    del_body((void*)p, (void**)&PL_ ## lctype ## _root)
 
 /* But for some types, we cheat. The type starts with some members that are
    never accessed. So we allocate the substructure, starting at the first used
@@ -1174,9 +1173,9 @@ S_del_body(pTHX_ void *thing, void **root)
 
 
 #define del_body_allocated(p,TYPE,lctype,member)                       \
-    S_del_body(aTHX_ (void*)((char*)p + STRUCT_OFFSET(TYPE, member)    \
-                            - STRUCT_OFFSET(lctype ## _allocated, member)), \
-                            (void**)&PL_ ## lctype ## _root)
+    del_body((void*)((char*)p + STRUCT_OFFSET(TYPE, member)            \
+                    - STRUCT_OFFSET(lctype ## _allocated, member)),    \
+            (void**)&PL_ ## lctype ## _root)
 
 #define my_safemalloc(s)       (void*)safemalloc(s)
 #define my_safefree(p) safefree((char*)p)
@@ -1219,7 +1218,7 @@ S_del_body(pTHX_ void *thing, void **root)
 #else /* !PURIFY */
 
 #define new_XNV()      new_body(NV, xnv)
-#define del_XNV(p)     del_body(p, NV, xnv)
+#define del_XNV(p)     del_body_type(p, NV, xnv)
 
 #define new_XPV()      new_body_allocated(XPV, xpv, xpv_cur)
 #define del_XPV(p)     del_body_allocated(p, XPV, xpv, xpv_cur)
@@ -1228,10 +1227,10 @@ S_del_body(pTHX_ void *thing, void **root)
 #define del_XPVIV(p)   del_body_allocated(p, XPVIV, xpviv, xpv_cur)
 
 #define new_XPVNV()    new_body(XPVNV, xpvnv)
-#define del_XPVNV(p)   del_body(p, XPVNV, xpvnv)
+#define del_XPVNV(p)   del_body_type(p, XPVNV, xpvnv)
 
 #define new_XPVCV()    new_body(XPVCV, xpvcv)
-#define del_XPVCV(p)   del_body(p, XPVCV, xpvcv)
+#define del_XPVCV(p)   del_body_type(p, XPVCV, xpvcv)
 
 #define new_XPVAV()    new_body_allocated(XPVAV, xpvav, xav_fill)
 #define del_XPVAV(p)   del_body_allocated(p, XPVAV, xpvav, xav_fill)
@@ -1240,16 +1239,16 @@ S_del_body(pTHX_ void *thing, void **root)
 #define del_XPVHV(p)   del_body_allocated(p, XPVHV, xpvhv, xhv_fill)
 
 #define new_XPVMG()    new_body(XPVMG, xpvmg)
-#define del_XPVMG(p)   del_body(p, XPVMG, xpvmg)
+#define del_XPVMG(p)   del_body_type(p, XPVMG, xpvmg)
 
 #define new_XPVGV()    new_body(XPVGV, xpvgv)
-#define del_XPVGV(p)   del_body(p, XPVGV, xpvgv)
+#define del_XPVGV(p)   del_body_type(p, XPVGV, xpvgv)
 
 #define new_XPVLV()    new_body(XPVLV, xpvlv)
-#define del_XPVLV(p)   del_body(p, XPVLV, xpvlv)
+#define del_XPVLV(p)   del_body_type(p, XPVLV, xpvlv)
 
 #define new_XPVBM()    new_body(XPVBM, xpvbm)
-#define del_XPVBM(p)   del_body(p, XPVBM, xpvbm)
+#define del_XPVBM(p)   del_body_type(p, XPVBM, xpvbm)
 
 #endif /* PURIFY */
 
@@ -1276,7 +1275,11 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt)
     size_t     old_body_offset;
     size_t     old_body_length;        /* Well, the length to copy.  */
     void*      old_body;
+#ifndef NV_ZERO_IS_ALLBITS_ZERO
+    /* If NV 0.0 is store as all bits 0 then Zero() already creates a correct
+       0.0 for us.  */
     bool       zero_nv = TRUE;
+#endif
     void*      new_body;
     size_t     new_body_length;
     size_t     new_body_offset;
@@ -1353,8 +1356,9 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt)
     case SVt_NV:
        old_body_arena = (void **) &PL_xnv_root;
        old_body_length = sizeof(NV);
+#ifndef NV_ZERO_IS_ALLBITS_ZERO
        zero_nv = FALSE;
-
+#endif
        if (mt < SVt_PVNV)
            mt = SVt_PVNV;
        break;
@@ -1384,7 +1388,9 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt)
        old_body_arena = (void **) &PL_xpvnv_root;
        old_body_length = STRUCT_OFFSET(XPVNV, xiv_u)
            + sizeof (((XPVNV*)SvANY(sv))->xiv_u);
+#ifndef NV_ZERO_IS_ALLBITS_ZERO
        zero_nv = FALSE;
+#endif
        break;
     case SVt_PVMG:
        /* Because the XPVMG of PL_mess_sv isn't allocated from the arena,
@@ -1398,7 +1404,9 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt)
        old_body_arena = (void **) &PL_xpvmg_root;
        old_body_length = STRUCT_OFFSET(XPVMG, xmg_stash)
            + sizeof (((XPVMG*)SvANY(sv))->xmg_stash);
+#ifndef NV_ZERO_IS_ALLBITS_ZERO
        zero_nv = FALSE;
+#endif
        break;
     default:
        Perl_croak(aTHX_ "Can't upgrade that kind of scalar");
@@ -1521,43 +1529,43 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt)
        new_body_arenaroot = (void **) &PL_xpv_arenaroot;
     new_body_no_NV:
        /* PV and PVIV don't have an NV slot.  */
+#ifndef NV_ZERO_IS_ALLBITS_ZERO
        zero_nv = FALSE;
+#endif
 
-       {
-       new_body:
-           assert(new_body_length);
+    new_body:
+       assert(new_body_length);
 #ifndef PURIFY
-           /* This points to the start of the allocated area.  */
-           new_body = S_new_body(aTHX_ new_body_arenaroot, new_body_arena,
-                                 new_body_length);
+       /* This points to the start of the allocated area.  */
+       new_body = S_new_body(aTHX_ new_body_arenaroot, new_body_arena,
+                             new_body_length);
 #else
-           /* We always allocated the full length item with PURIFY */
-           new_body_length += new_body_offset;
-           new_body_offset = 0;
-           new_body = my_safemalloc(new_body_length);
+       /* We always allocated the full length item with PURIFY */
+       new_body_length += new_body_offset;
+       new_body_offset = 0;
+       new_body = my_safemalloc(new_body_length);
 
 #endif
-       zero:
-           Zero(new_body, new_body_length, char);
-           new_body = ((char *)new_body) - new_body_offset;
-           SvANY(sv) = new_body;
-
-           if (old_body_length) {
-               Copy((char *)old_body + old_body_offset,
-                    (char *)new_body + old_body_offset,
-                    old_body_length, char);
-           }
+    zero:
+       Zero(new_body, new_body_length, char);
+       new_body = ((char *)new_body) - new_body_offset;
+       SvANY(sv) = new_body;
 
-           /* FIXME - add a Configure test to determine if NV 0.0 is actually
-              all bits zero. If it is, we can skip this initialisation.  */
-           if (zero_nv)
-               SvNV_set(sv, 0);
-
-           if (mt == SVt_PVIO)
-               IoPAGE_LEN(sv)  = 60;
-           if (old_type < SVt_RV)
-               SvPV_set(sv, 0);
+       if (old_body_length) {
+           Copy((char *)old_body + old_body_offset,
+                (char *)new_body + old_body_offset,
+                old_body_length, char);
        }
+
+#ifndef NV_ZERO_IS_ALLBITS_ZERO
+       if (zero_nv)
+           SvNV_set(sv, 0);
+#endif
+
+       if (mt == SVt_PVIO)
+           IoPAGE_LEN(sv)      = 60;
+       if (old_type < SVt_RV)
+           SvPV_set(sv, 0);
        break;
     default:
        Perl_croak(aTHX_ "panic: sv_upgrade to unknown type %lu", mt);
@@ -1568,8 +1576,8 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt)
 #ifdef PURIFY
        my_safefree(old_body);
 #else
-       S_del_body(aTHX_ (void*)((char*)old_body + old_body_offset),
-                  old_body_arena);
+       del_body((void*)((char*)old_body + old_body_offset),
+                old_body_arena);
 #endif
     }
 }
@@ -10095,7 +10103,7 @@ Perl_ptr_table_new(pTHX)
 #endif
 
 #define new_pte()      new_body(struct ptr_tbl_ent, pte)
-#define del_pte(p)     del_body(p, struct ptr_tbl_ent, pte)
+#define del_pte(p)     del_body_type(p, struct ptr_tbl_ent, pte)
 
 /* map an existing pointer using a table */