Zero-ing the new HV array is pointless, as we write to every element.
authorNicholas Clark <nick@ccl4.org>
Wed, 1 Jun 2005 15:23:02 +0000 (15:23 +0000)
committerNicholas Clark <nick@ccl4.org>
Wed, 1 Jun 2005 15:23:02 +0000 (15:23 +0000)
Also avoid calling into he_dup when the HE is 0, to save the function
call overhead.

p4raw-id: //depot/perl@24662

sv.c

diff --git a/sv.c b/sv.c
index 33584a3..30aa440 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -10926,18 +10926,18 @@ Perl_sv_dup(pTHX_ SV *sstr, CLONE_PARAMS* param)
 
            if (HvARRAY((HV*)sstr)) {
                STRLEN i = 0;
+               bool sharekeys = !!HvSHAREKEYS(sstr);
                XPVHV *dxhv = (XPVHV*)SvANY(dstr);
                XPVHV *sxhv = (XPVHV*)SvANY(sstr);
                char *darray;
-               /* FIXME - surely this doesn't need to be zeroed?  */
-               Newz(0, darray,
+               New(0, darray,
                     PERL_HV_ARRAY_ALLOC_BYTES(dxhv->xhv_max+1)
                     + (SvOOK(sstr) ? sizeof(struct xpvhv_aux) : 0), char);
                HvARRAY(dstr) = (HE**)darray;
                while (i <= sxhv->xhv_max) {
+                   HE *source = HvARRAY(sstr)[i];
                    HvARRAY(dstr)[i]
-                       = he_dup(HvARRAY(sstr)[i],
-                                (bool)!!HvSHAREKEYS(sstr), param);
+                       = source ? he_dup(source, sharekeys, param) : 0;
                    ++i;
                }
                if (SvOOK(sstr)) {