diff options
author | Nicholas Clark <nick@ccl4.org> | 2005-07-02 12:34:08 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2005-07-02 12:34:08 +0000 |
commit | 43c5f42db1e336a99904bcc798b7070727bfbd0a (patch) | |
tree | 1e02933dfd6fac99b7933947f33451769fd8467e | |
parent | 0cf8ddea3351f0ff9eef736dfa13bc866d0d1f97 (diff) | |
download | perl-43c5f42db1e336a99904bcc798b7070727bfbd0a.tar.gz |
Don't check the pointer is non-NULL before calling Safefree() in
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
-rw-r--r-- | doio.c | 12 | ||||
-rw-r--r-- | locale.c | 15 | ||||
-rw-r--r-- | mg.c | 15 | ||||
-rw-r--r-- | perl.c | 9 | ||||
-rw-r--r-- | perl.h | 2 | ||||
-rw-r--r-- | regcomp.c | 17 | ||||
-rw-r--r-- | sv.c | 3 | ||||
-rw-r--r-- | util.c | 3 |
8 files changed, 26 insertions, 50 deletions
@@ -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) @@ -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; } @@ -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); @@ -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); } @@ -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 { \ @@ -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); @@ -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; @@ -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); |