Skip to content

Commit

Permalink
Merge pull request #2862 from hedaoyuan/fix_14
Browse files Browse the repository at this point in the history
Remove useless empty pointer check.
  • Loading branch information
hedaoyuan authored Jul 14, 2017
2 parents 581cf90 + 010adb9 commit 3f5e650
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 37 deletions.
12 changes: 2 additions & 10 deletions paddle/api/ConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ ModelConfig* TrainerConfig::getModelConfig() const {

ParameterConfig::ParameterConfig() : m(new ParameterConfigPrivate()) {}

ParameterConfig::~ParameterConfig() {
if (m) {
delete m;
}
}
ParameterConfig::~ParameterConfig() { delete m; }

ParameterConfig* ParameterConfig::createParameterConfigFromParameterSharedPtr(
void* ptr) {
Expand Down Expand Up @@ -98,11 +94,7 @@ void* ParameterConfig::getRawPtr() { return m->getConfigPtr(); }

OptimizationConfig::OptimizationConfig() : m(new OptimizationConfigPrivate()) {}

OptimizationConfig::~OptimizationConfig() {
if (m) {
delete m;
}
}
OptimizationConfig::~OptimizationConfig() { delete m; }

std::string OptimizationConfig::toProtoString() {
return m->getConfig().SerializeAsString();
Expand Down
12 changes: 2 additions & 10 deletions paddle/api/ParameterOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ struct ParameterTraverseCallbackPrivate {

ParameterOptimizer::ParameterOptimizer() : m(new ParameterOptimizerPrivate()) {}

ParameterOptimizer::~ParameterOptimizer() {
if (m) {
delete m;
}
}
ParameterOptimizer::~ParameterOptimizer() { delete m; }

ParameterOptimizer* ParameterOptimizer::create(OptimizationConfig* config) {
CHECK(config != nullptr);
Expand Down Expand Up @@ -104,11 +100,7 @@ std::vector<int> ParameterOptimizer::getParameterTypes() const {
ParameterTraverseCallback::ParameterTraverseCallback()
: m(new ParameterTraverseCallbackPrivate()) {}

ParameterTraverseCallback::~ParameterTraverseCallback() {
if (m) {
delete m;
}
}
ParameterTraverseCallback::~ParameterTraverseCallback() { delete m; }

void ParameterTraverseCallback::apply(const std::vector<Vector*>& vecs,
const ParameterConfig& conf,
Expand Down
6 changes: 1 addition & 5 deletions paddle/api/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ struct VectorPrivate {

Vector::Vector() : m(new VectorPrivate()) {}

Vector::~Vector() {
if (m) {
delete m;
}
}
Vector::~Vector() { delete m; }

Vector* Vector::createZero(size_t sz, bool useGpu) {
auto retVec = new Vector();
Expand Down
6 changes: 2 additions & 4 deletions paddle/gserver/dataproviders/DataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ class BufferBatch {
hl_destroy_event(hlEvent_);
hlEvent_ = NULL;
}
if (batchData_) {
delete batchData_;
batchData_ = NULL;
}
delete batchData_;
batchData_ = NULL;
}

void setDataBatch(DataBatch* batchData) { batchData_ = batchData; }
Expand Down
4 changes: 1 addition & 3 deletions paddle/math/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ static InitFunction __init_storage_engine([]() { StorageEngine::singleton(); },
StorageEngine::StorageEngine() : cpuAllocator_(nullptr) {}

StorageEngine::~StorageEngine() {
if (cpuAllocator_) {
delete cpuAllocator_;
}
delete cpuAllocator_;
for (auto it : gpuAllocator_) {
delete it;
}
Expand Down
6 changes: 1 addition & 5 deletions paddle/trainer/TrainerConfigHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ TrainerConfigHelper::TrainerConfigHelper(const TrainerConfig &config)
m->conf = config;
}

TrainerConfigHelper::~TrainerConfigHelper() {
if (m) {
delete m;
}
}
TrainerConfigHelper::~TrainerConfigHelper() { delete m; }

const TrainerConfig &TrainerConfigHelper::getConfig() const { return m->conf; }

Expand Down

0 comments on commit 3f5e650

Please sign in to comment.