This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
simplify hv_clear
authorDavid Mitchell <davem@iabyn.com>
Tue, 26 Apr 2011 15:07:50 +0000 (16:07 +0100)
committerDavid Mitchell <davem@iabyn.com>
Thu, 19 May 2011 13:49:42 +0000 (14:49 +0100)
Don't use a goto when an else will do

i.e. replace

    if (..) {
        A
        goto reset
    }
    B
    reset:

with

    if (..) {
        A
    }
    else {
        B
    }

hv.c

diff --git a/hv.c b/hv.c
index 390eba8..a37ed09 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -1548,20 +1548,19 @@ Perl_hv_clear(pTHX_ HV *hv)
                }
            }
        }
-       goto reset;
     }
+    else {
+       hfreeentries(hv);
+       HvPLACEHOLDERS_set(hv, 0);
+       if (HvARRAY(hv))
+           Zero(HvARRAY(hv), xhv->xhv_max+1 /* HvMAX(hv)+1 */, HE*);
 
-    hfreeentries(hv);
-    HvPLACEHOLDERS_set(hv, 0);
-    if (HvARRAY(hv))
-       Zero(HvARRAY(hv), xhv->xhv_max+1 /* HvMAX(hv)+1 */, HE*);
-
-    if (SvRMAGICAL(hv))
-       mg_clear(MUTABLE_SV(hv));
+       if (SvRMAGICAL(hv))
+           mg_clear(MUTABLE_SV(hv));
 
-    HvHASKFLAGS_off(hv);
-    HvREHASH_off(hv);
-    reset:
+       HvHASKFLAGS_off(hv);
+       HvREHASH_off(hv);
+    }
     if (SvOOK(hv)) {
         if(HvENAME_get(hv))
             mro_isa_changed_in(hv);