From d7ae1ed204e346760a717e6c52cc07d63c7d6d17 Mon Sep 17 00:00:00 2001 From: Cary R Date: Thu, 22 Apr 2010 10:25:14 -0700 Subject: [PATCH] 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. --- net_link.cc | 12 ++++-------- vvp/array.cc | 6 ++---- vvp/vvp_island.cc | 28 +++++++++++----------------- vvp/vvp_net.cc | 6 ++---- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/net_link.cc b/net_link.cc index 8b5ee05b8..facc8c5f9 100644 --- a/net_link.cc +++ b/net_link.cc @@ -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); diff --git a/vvp/array.cc b/vvp/array.cc index 7cd1628fa..f4954df9f 100644 --- a/vvp/array.cc +++ b/vvp/array.cc @@ -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 diff --git a/vvp/vvp_island.cc b/vvp/vvp_island.cc index 420e5a9e6..6b4a76343 100644 --- a/vvp/vvp_island.cc +++ b/vvp/vvp_island.cc @@ -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; } diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index dc676fae4..787c32f31 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -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;