This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move the code handling allocating a new buffer earlier in Perl_hv_ksplit().
authorNicholas Clark <nick@ccl4.org>
Thu, 21 Feb 2013 18:16:44 +0000 (19:16 +0100)
committerNicholas Clark <nick@ccl4.org>
Tue, 26 Feb 2013 15:00:19 +0000 (16:00 +0100)
This makes the rest of the code of Perl_hv_ksplit() closer to that of
S_hsplit().

hv.c

diff --git a/hv.c b/hv.c
index acb8d0a..8b447c8 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -1176,7 +1176,14 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax)
        return;                                 /* overflow detection */
 
     a = (char *) HvARRAY(hv);
-    if (a) {
+    if (!a) {
+        Newxz(a, PERL_HV_ARRAY_ALLOC_BYTES(newsize), char);
+        xhv->xhv_max = --newsize;
+        HvARRAY(hv) = (HE **) a;
+        return;
+    }
+
+    {
        PL_nomemok = TRUE;
        Renew(a, PERL_HV_ARRAY_ALLOC_BYTES(newsize)
              + (SvOOK(hv) ? sizeof(struct xpvhv_aux) : 0), char);
@@ -1190,9 +1197,6 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax)
        PL_nomemok = FALSE;
        Zero(&a[oldsize * sizeof(HE*)], (newsize-oldsize) * sizeof(HE*), char); /* zero 2nd half*/
     }
-    else {
-       Newxz(a, PERL_HV_ARRAY_ALLOC_BYTES(newsize), char);
-    }
     xhv->xhv_max = --newsize;  /* HvMAX(hv) = --newsize */
     HvARRAY(hv) = (HE **) a;
     if (!xhv->xhv_keys /* !HvTOTALKEYS(hv) */) /* skip rest if no entries */