Don't check the pointer is non-NULL before calling Safefree() in
Nicholas Clark [Sat, 2 Jul 2005 12:34:08 +0000 (12:34 +0000)]
little used code, code used only once per run (such as interpreter
construction and destruction), and cases where the pointer nearly
never is NULL. Safefree does its own non-NULL check, and even that
isn't strictly necessary as all conformant free()s accept a NULL
pointer.

p4raw-id: //depot/perl@25045

doio.c
locale.c
mg.c
perl.c
perl.h
regcomp.c
sv.c
util.c

diff --git a/doio.c b/doio.c
index b62a473..c1b11d3 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1497,14 +1497,10 @@ Perl_do_aexec5(pTHX_ SV *really, register SV **mark, register SV **sp,
 void
 Perl_do_execfree(pTHX)
 {
-    if (PL_Argv) {
-       Safefree(PL_Argv);
-       PL_Argv = Null(char **);
-    }
-    if (PL_Cmd) {
-       Safefree(PL_Cmd);
-       PL_Cmd = Nullch;
-    }
+    Safefree(PL_Argv);
+    PL_Argv = Null(char **);
+    Safefree(PL_Cmd);
+    PL_Cmd = Nullch;
 }
 
 #if !defined(OS2) && !defined(WIN32) && !defined(DJGPP) && !defined(EPOC) && !defined(SYMBIAN) && !defined(MACOS_TRADITIONAL)
index 77a83fd..40d2a44 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -112,10 +112,8 @@ Perl_new_numeric(pTHX_ const char *newnum)
 #ifdef USE_LOCALE_NUMERIC
 
     if (! newnum) {
-       if (PL_numeric_name) {
-           Safefree(PL_numeric_name);
-           PL_numeric_name = NULL;
-       }
+       Safefree(PL_numeric_name);
+       PL_numeric_name = NULL;
        PL_numeric_standard = TRUE;
        PL_numeric_local = TRUE;
        return;
@@ -534,16 +532,13 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
 #endif
 
 #ifdef USE_LOCALE_CTYPE
-    if (curctype != NULL)
-       Safefree(curctype);
+    Safefree(curctype);
 #endif /* USE_LOCALE_CTYPE */
 #ifdef USE_LOCALE_COLLATE
-    if (curcoll != NULL)
-       Safefree(curcoll);
+    Safefree(curcoll);
 #endif /* USE_LOCALE_COLLATE */
 #ifdef USE_LOCALE_NUMERIC
-    if (curnum != NULL)
-       Safefree(curnum);
+    Safefree(curnum);
 #endif /* USE_LOCALE_NUMERIC */
     return ok;
 }
diff --git a/mg.c b/mg.c
index dcc3a90..6d82070 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -2215,19 +2215,12 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
        PL_hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
        break;
     case '\011':       /* ^I */ /* NOT \t in EBCDIC */
-       if (PL_inplace)
-           Safefree(PL_inplace);
-       if (SvOK(sv))
-           PL_inplace = savesvpv(sv);
-       else
-           PL_inplace = Nullch;
-       break;
+       Safefree(PL_inplace);
+       PL_inplace = SvOK(sv) ? savesvpv(sv) : Nullch;
     case '\017':       /* ^O */
        if (*(mg->mg_ptr+1) == '\0') {
-           if (PL_osname) {
-               Safefree(PL_osname);
-               PL_osname = Nullch;
-           }
+           Safefree(PL_osname);
+           PL_osname = Nullch;
            if (SvOK(sv)) {
                TAINT_PROPER("assigning to $^O");
                PL_osname = savesvpv(sv);
diff --git a/perl.c b/perl.c
index 5d5ec62..4bafb31 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1208,8 +1208,7 @@ perl_destruct(pTHXx)
     Safefree(PL_reg_start_tmp);
     PL_reg_start_tmp = (char**)NULL;
     PL_reg_start_tmpl = 0;
-    if (PL_reg_curpm)
-       Safefree(PL_reg_curpm);
+    Safefree(PL_reg_curpm);
     Safefree(PL_reg_poscache);
     free_tied_hv_pool();
     Safefree(PL_op_mask);
@@ -2968,8 +2967,7 @@ Perl_moreswitches(pTHX_ char *s)
        usage(PL_origargv[0]);
        my_exit(0);
     case 'i':
-       if (PL_inplace)
-           Safefree(PL_inplace);
+       Safefree(PL_inplace);
 #if defined(__CYGWIN__) /* do backup extension automagically */
        if (*(s+1) == '\0') {
        PL_inplace = savepv(".bak");
@@ -4405,8 +4403,7 @@ S_init_predump_symbols(pTHX)
 
     PL_statname = NEWSV(66,0);         /* last filename we did stat on */
 
-    if (PL_osname)
-       Safefree(PL_osname);
+    Safefree(PL_osname);
     PL_osname = savepv(OSNAME);
 }
 
diff --git a/perl.h b/perl.h
index 9de1291..22d41f1 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -4764,7 +4764,7 @@ typedef struct am_table_short AMTS;
        new_chunk = (void *)(chunk);                       \
        new_chunk_size = (chunk_size);                     \
        if (new_chunk_size > PL_nice_chunk_size) {         \
-           if (PL_nice_chunk) Safefree(PL_nice_chunk);    \
+           Safefree(PL_nice_chunk);                       \
            PL_nice_chunk = (char *) new_chunk;            \
            PL_nice_chunk_size = new_chunk_size;           \
        } else {                                           \
index d2526b7..57f5834 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -6007,10 +6007,10 @@ Perl_pregfree(pTHX_ struct regexp *r)
                       len > 60 ? "..." : "");
     });
 
-    if (r->precomp)
-       Safefree(r->precomp);
-    if (r->offsets)             /* 20010421 MJD */
-       Safefree(r->offsets);
+    /* gcov results gave these as non-null 100% of the time, so there's no
+       optimisation in checking them before calling Safefree  */
+    Safefree(r->precomp);
+    Safefree(r->offsets);             /* 20010421 MJD */
     RX_MATCH_COPY_FREE(r);
 #ifdef PERL_OLD_COPY_ON_WRITE
     if (r->saved_copy)
@@ -6073,14 +6073,11 @@ Perl_pregfree(pTHX_ struct regexp *r)
                        refcount = trie->refcount--;
                        OP_REFCNT_UNLOCK;
                        if ( !refcount ) {
-                           if (trie->charmap)
-                               Safefree(trie->charmap);
+                           Safefree(trie->charmap);
                            if (trie->widecharmap)
                                SvREFCNT_dec((SV*)trie->widecharmap);
-                           if (trie->states)
-                               Safefree(trie->states);
-                           if (trie->trans)
-                               Safefree(trie->trans);
+                           Safefree(trie->states);
+                           Safefree(trie->trans);
 #ifdef DEBUGGING
                            if (trie->words)
                                SvREFCNT_dec((SV*)trie->words);
diff --git a/sv.c b/sv.c
index 35af580..e3a8a29 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -572,8 +572,7 @@ Perl_sv_free_arenas(pTHX)
     free_arena(pte);
 #endif
 
-    if (PL_nice_chunk)
-       Safefree(PL_nice_chunk);
+    Safefree(PL_nice_chunk);
     PL_nice_chunk = Nullch;
     PL_nice_chunk_size = 0;
     PL_sv_arenaroot = 0;
diff --git a/util.c b/util.c
index 4da13d4..c65ccce 100644 (file)
--- a/util.c
+++ b/util.c
@@ -2959,8 +2959,7 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, const char **searc
            }
            scriptname = Nullch;
        }
-       if (xfailed)
-           Safefree(xfailed);
+       Safefree(xfailed);
        scriptname = xfound;
     }
     return (scriptname ? savepv(scriptname) : Nullch);