No need to have an if for a delete (found with cppcheck).

It is acceptable to call delete on a NULL object. It's also acceptable
to assign the value to zero if it is already zero. Removing the
superfluous if should produce slightly better code since there is no
conditional to deal with except for what is likely in the delete
implementation, but that should be highly optimized.
This commit is contained in:
Cary R 2010-04-22 10:25:14 -07:00 committed by Stephen Williams
parent b91657dbb9
commit d7ae1ed204
4 changed files with 19 additions and 33 deletions

View File

@ -36,10 +36,8 @@ void Nexus::connect(Link&r)
if (this == r_nexus)
return;
if (name_) {
delete[]name_;
name_ = 0;
}
delete[] name_;
name_ = 0;
// Special case: This nexus is empty. Simply copy all the
// links of the other nexus to this one, and delete the old
@ -367,10 +365,8 @@ void Nexus::drivers_drive(ivl_drive_t drive0, ivl_drive_t drive1)
void Nexus::unlink(Link*that)
{
if (name_) {
delete[] name_;
name_ = 0;
}
delete[] name_;
name_ = 0;
assert(that);

View File

@ -1663,10 +1663,8 @@ vpiHandle vpip_make_vthr_A(char*label, vpiHandle handle)
void compile_array_cleanup(void)
{
if (array_table) {
delete array_table;
array_table = 0;
}
delete array_table;
array_table = 0;
}
#ifdef CHECK_WITH_VALGRIND

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008-2009 Stephen Williams (steve@icarus.com)
* Copyright (c) 2008-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -147,18 +147,14 @@ vvp_net_t* vvp_island::find_port(const char*key)
void vvp_island::compile_cleanup()
{
if (ports_) {
delete ports_;
ports_ = 0;
}
if (anodes_) {
delete anodes_;
anodes_ = 0;
}
if (bnodes_) {
delete bnodes_;
bnodes_ = 0;
}
delete ports_;
ports_ = 0;
delete anodes_;
anodes_ = 0;
delete bnodes_;
bnodes_ = 0;
}
vvp_island_port::vvp_island_port(vvp_island*ip)
@ -371,8 +367,6 @@ void compile_island_cleanup(void)
#endif
// Remove the island symbol table itself.
if (island_table) {
delete island_table;
island_table = 0;
}
delete island_table;
island_table = 0;
}

View File

@ -2020,10 +2020,8 @@ vvp_vector2_t& vvp_vector2_t::operator= (const vvp_vector2_t&that)
if (this == &that)
return *this;
if (vec_) {
delete[]vec_;
vec_ = 0;
}
delete[] vec_;
vec_ = 0;
copy_from_that_(that);
return *this;