Skip to content

Commit 1b2677a

Browse files
committed
Remove nullptr checks before destructor
It is not needed because delete accepts a nullptr argument. Signed-off-by: Stefan Weil <[email protected]>
1 parent e2ab699 commit 1b2677a

20 files changed

+57
-116
lines changed

api/baseapi.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -2300,10 +2300,8 @@ void TessBaseAPI::ClearResults() {
23002300
if (tesseract_ != nullptr) {
23012301
tesseract_->Clear();
23022302
}
2303-
if (page_res_ != nullptr) {
2304-
delete page_res_;
2305-
page_res_ = nullptr;
2306-
}
2303+
delete page_res_;
2304+
page_res_ = nullptr;
23072305
recognition_done_ = false;
23082306
if (block_list_ == nullptr)
23092307
block_list_ = new BLOCK_LIST;

ccmain/equationdetect.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,7 @@ void EquationDetect::ComputeCPsSuperBBox() {
790790
ColPartitionGridSearch gsearch(part_grid_);
791791
ColPartition *part = nullptr;
792792
gsearch.StartFullSearch();
793-
if (cps_super_bbox_) {
794-
delete cps_super_bbox_;
795-
}
793+
delete cps_super_bbox_;
796794
cps_super_bbox_ = new TBOX();
797795
while ((part = gsearch.NextFullSearch()) != nullptr) {
798796
(*cps_super_bbox_) += part->bounding_box();

ccstruct/blobbox.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,7 @@ static void clear_blobnboxes(BLOBNBOX_LIST* boxes) {
927927
// have to delete them explicitly.
928928
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
929929
BLOBNBOX* box = it.data();
930-
if (box->cblob() != nullptr)
931-
delete box->cblob();
930+
delete box->cblob();
932931
}
933932
}
934933

ccstruct/normalis.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,12 @@ void DENORM::Print() const {
541541

542542
// Free allocated memory and clear pointers.
543543
void DENORM::Clear() {
544-
if (x_map_ != nullptr) {
545-
delete x_map_;
546-
x_map_ = nullptr;
547-
}
548-
if (y_map_ != nullptr) {
549-
delete y_map_;
550-
y_map_ = nullptr;
551-
}
552-
if (rotation_ != nullptr) {
553-
delete rotation_;
554-
rotation_ = nullptr;
555-
}
544+
delete x_map_;
545+
x_map_ = nullptr;
546+
delete y_map_;
547+
y_map_ = nullptr;
548+
delete rotation_;
549+
rotation_ = nullptr;
556550
}
557551

558552
// Setup default values.

ccstruct/pageres.cpp

+16-31
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,7 @@ void WERD_RES::ReplaceBestChoice(WERD_CHOICE* choice) {
799799
// the best_choice->state.
800800
void WERD_RES::RebuildBestState() {
801801
ASSERT_HOST(best_choice != nullptr);
802-
if (rebuild_word != nullptr)
803-
delete rebuild_word;
802+
delete rebuild_word;
804803
rebuild_word = new TWERD;
805804
if (seam_array.empty())
806805
start_seam_list(chopped_word, &seam_array);
@@ -826,8 +825,7 @@ void WERD_RES::RebuildBestState() {
826825
// Copies the chopped_word to the rebuild_word, faking a best_state as well.
827826
// Also sets up the output box_word.
828827
void WERD_RES::CloneChoppedToRebuild() {
829-
if (rebuild_word != nullptr)
830-
delete rebuild_word;
828+
delete rebuild_word;
831829
rebuild_word = new TWERD(*chopped_word);
832830
SetupBoxWord();
833831
int word_len = box_word->length();
@@ -841,8 +839,7 @@ void WERD_RES::CloneChoppedToRebuild() {
841839

842840
// Sets/replaces the box_word with one made from the rebuild_word.
843841
void WERD_RES::SetupBoxWord() {
844-
if (box_word != nullptr)
845-
delete box_word;
842+
delete box_word;
846843
rebuild_word->ComputeBoundingBoxes();
847844
box_word = tesseract::BoxWord::CopyFromNormalized(rebuild_word);
848845
box_word->ClipToOriginalWord(denorm.block(), word);
@@ -1130,7 +1127,7 @@ void WERD_RES::InitPointers() {
11301127
}
11311128

11321129
void WERD_RES::Clear() {
1133-
if (word != nullptr && combination) {
1130+
if (combination) {
11341131
delete word;
11351132
}
11361133
word = nullptr;
@@ -1145,23 +1142,15 @@ void WERD_RES::ClearResults() {
11451142
fontinfo2 = nullptr;
11461143
fontinfo_id_count = 0;
11471144
fontinfo_id2_count = 0;
1148-
if (bln_boxes != nullptr) {
1149-
delete bln_boxes;
1150-
bln_boxes = nullptr;
1151-
}
1145+
delete bln_boxes;
1146+
bln_boxes = nullptr;
11521147
blob_row = nullptr;
1153-
if (chopped_word != nullptr) {
1154-
delete chopped_word;
1155-
chopped_word = nullptr;
1156-
}
1157-
if (rebuild_word != nullptr) {
1158-
delete rebuild_word;
1159-
rebuild_word = nullptr;
1160-
}
1161-
if (box_word != nullptr) {
1162-
delete box_word;
1163-
box_word = nullptr;
1164-
}
1148+
delete chopped_word;
1149+
chopped_word = nullptr;
1150+
delete rebuild_word;
1151+
rebuild_word = nullptr;
1152+
delete box_word;
1153+
box_word = nullptr;
11651154
best_state.clear();
11661155
correct_text.clear();
11671156
seam_array.delete_data_pointers();
@@ -1174,15 +1163,11 @@ void WERD_RES::ClearResults() {
11741163
}
11751164
void WERD_RES::ClearWordChoices() {
11761165
best_choice = nullptr;
1177-
if (raw_choice != nullptr) {
1178-
delete raw_choice;
1179-
raw_choice = nullptr;
1180-
}
1166+
delete raw_choice;
1167+
raw_choice = nullptr;
11811168
best_choices.clear();
1182-
if (ep_choice != nullptr) {
1183-
delete ep_choice;
1184-
ep_choice = nullptr;
1185-
}
1169+
delete ep_choice;
1170+
ep_choice = nullptr;
11861171
}
11871172
void WERD_RES::ClearRatings() {
11881173
if (ratings != nullptr) {

ccutil/genericvector.h

+7-12
Original file line numberDiff line numberDiff line change
@@ -864,22 +864,17 @@ void GenericVector<T>::clear() {
864864
size_used_ = 0;
865865
size_reserved_ = 0;
866866
}
867-
if (clear_cb_ != nullptr) {
868-
delete clear_cb_;
869-
clear_cb_ = nullptr;
870-
}
871-
if (compare_cb_ != nullptr) {
872-
delete compare_cb_;
873-
compare_cb_ = nullptr;
874-
}
867+
delete clear_cb_;
868+
clear_cb_ = nullptr;
869+
delete compare_cb_;
870+
compare_cb_ = nullptr;
875871
}
876872

877873
template <typename T>
878874
void GenericVector<T>::delete_data_pointers() {
879-
for (int i = 0; i < size_used_; ++i)
880-
if (data_[i]) {
881-
delete data_[i];
882-
}
875+
for (int i = 0; i < size_used_; ++i) {
876+
delete data_[i];
877+
}
883878
}
884879

885880

ccutil/unicharmap.cpp

+4-10
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ nodes(nullptr) {
2727
}
2828

2929
UNICHARMAP::~UNICHARMAP() {
30-
if (nodes != nullptr)
31-
delete[] nodes;
30+
delete[] nodes;
3231
}
3332

3433
// Search the given unichar representation in the tree, using length characters
@@ -116,11 +115,8 @@ int UNICHARMAP::minmatch(const char* const unichar_repr) const {
116115
}
117116

118117
void UNICHARMAP::clear() {
119-
if (nodes != nullptr)
120-
{
121-
delete[] nodes;
122-
nodes = nullptr;
123-
}
118+
delete[] nodes;
119+
nodes = nullptr;
124120
}
125121

126122
UNICHARMAP::UNICHARMAP_NODE::UNICHARMAP_NODE() :
@@ -130,7 +126,5 @@ id(-1) {
130126

131127
// Recursively delete the children
132128
UNICHARMAP::UNICHARMAP_NODE::~UNICHARMAP_NODE() {
133-
if (children != nullptr) {
134-
delete[] children;
135-
}
129+
delete[] children;
136130
}

ccutil/unicharset.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,8 @@ class UNICHARSET {
292292
// Delete CHAR_FRAGMENTs stored in properties of unichars array.
293293
void delete_pointers_in_unichars() {
294294
for (int i = 0; i < size_used; ++i) {
295-
if (unichars[i].properties.fragment != nullptr) {
296-
delete unichars[i].properties.fragment;
297-
unichars[i].properties.fragment = nullptr;
298-
}
295+
delete unichars[i].properties.fragment;
296+
unichars[i].properties.fragment = nullptr;
299297
}
300298
}
301299

classify/adaptmatch.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,8 @@ void Classify::EndAdaptiveClassifier() {
499499
}
500500
delete shape_table_;
501501
shape_table_ = nullptr;
502-
if (static_classifier_ != nullptr) {
503-
delete static_classifier_;
504-
static_classifier_ = nullptr;
505-
}
502+
delete static_classifier_;
503+
static_classifier_ = nullptr;
506504
} /* EndAdaptiveClassifier */
507505

508506

classify/trainingsampleset.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ void TrainingSampleSet::OrganizeByFontAndClass() {
514514
SetupFontIdMap();
515515
int compact_font_size = font_id_map_.CompactSize();
516516
// Get a 2-d array of generic vectors.
517-
if (font_class_array_ != nullptr)
518-
delete font_class_array_;
517+
delete font_class_array_;
519518
FontClassInfo empty;
520519
font_class_array_ = new GENERIC_2D_ARRAY<FontClassInfo>(
521520
compact_font_size, unicharset_size_, empty);

textord/bbgrid.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,14 @@ IntGrid::IntGrid(int gridsize, const ICOORD& bleft, const ICOORD& tright)
7373
}
7474

7575
IntGrid::~IntGrid() {
76-
if (grid_ != nullptr)
77-
delete [] grid_;
76+
delete [] grid_;
7877
}
7978

8079
// (Re)Initialize the grid. The gridsize is the size in pixels of each cell,
8180
// and bleft, tright are the bounding box of everything to go in it.
8281
void IntGrid::Init(int gridsize, const ICOORD& bleft, const ICOORD& tright) {
8382
GridBase::Init(gridsize, bleft, tright);
84-
if (grid_ != nullptr)
85-
delete [] grid_;
83+
delete [] grid_;
8684
grid_ = new int[gridbuckets_];
8785
Clear();
8886
}

textord/bbgrid.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,7 @@ BBGrid<BBC, BBC_CLIST, BBC_C_IT>::BBGrid(
438438

439439
template<class BBC, class BBC_CLIST, class BBC_C_IT>
440440
BBGrid<BBC, BBC_CLIST, BBC_C_IT>::~BBGrid() {
441-
if (grid_ != nullptr)
442-
delete [] grid_;
441+
delete [] grid_;
443442
}
444443

445444
// (Re)Initialize the grid. The gridsize is the size in pixels of each cell,
@@ -449,8 +448,7 @@ void BBGrid<BBC, BBC_CLIST, BBC_C_IT>::Init(int gridsize,
449448
const ICOORD& bleft,
450449
const ICOORD& tright) {
451450
GridBase::Init(gridsize, bleft, tright);
452-
if (grid_ != nullptr)
453-
delete [] grid_;
451+
delete [] grid_;
454452
grid_ = new BBC_CLIST[gridbuckets_];
455453
}
456454

textord/colfind.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ ColumnFinder::ColumnFinder(int gridsize,
9797

9898
ColumnFinder::~ColumnFinder() {
9999
column_sets_.delete_data_pointers();
100-
if (best_columns_ != nullptr) {
101-
delete [] best_columns_;
102-
}
103-
if (stroke_width_ != nullptr)
104-
delete stroke_width_;
100+
delete [] best_columns_;
101+
delete stroke_width_;
105102
delete input_blobs_win_;
106103
pixDestroy(&nontext_map_);
107104
while (denorm_ != nullptr) {
@@ -147,8 +144,7 @@ void ColumnFinder::SetupAndFilterNoise(PageSegMode pageseg_mode,
147144
Pix* photo_mask_pix,
148145
TO_BLOCK* input_block) {
149146
part_grid_.Init(gridsize(), bleft(), tright());
150-
if (stroke_width_ != nullptr)
151-
delete stroke_width_;
147+
delete stroke_width_;
152148
stroke_width_ = new StrokeWidth(gridsize(), bleft(), tright());
153149
min_gutter_width_ = static_cast<int>(kMinGutterWidthGrid * gridsize());
154150
input_block->ReSetAndReFilterBlobs();

textord/devanagari_processing.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ class PixelHistogram {
4646
}
4747

4848
void Clear() {
49-
if (hist_) {
50-
delete[] hist_;
51-
}
49+
delete[] hist_;
5250
length_ = 0;
5351
}
5452

textord/fpchop.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,7 @@ C_OUTLINE *C_OUTLINE_FRAG::close() { //join pieces
812812
C_OUTLINE_FRAG & C_OUTLINE_FRAG::operator= (
813813
const C_OUTLINE_FRAG & src //fragment to copy
814814
) {
815-
if (steps != nullptr)
816-
delete [] steps;
815+
delete [] steps;
817816

818817
stepcount = src.stepcount;
819818
steps = new DIR128[stepcount];

textord/fpchop.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class C_OUTLINE_FRAG:public ELIST_LINK
3131
stepcount = 0;
3232
}
3333
~C_OUTLINE_FRAG () {
34-
if (steps != nullptr)
35-
delete [] steps;
34+
delete [] steps;
3635
}
3736
//start coord
3837
C_OUTLINE_FRAG(ICOORD start_pt,

textord/tabfind.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ TabFind::TabFind(int gridsize, const ICOORD& bleft, const ICOORD& tright,
7676
}
7777

7878
TabFind::~TabFind() {
79-
if (width_cb_ != nullptr)
80-
delete width_cb_;
79+
delete width_cb_;
8180
}
8281

8382
///////////////// PUBLIC functions (mostly used by TabVector). //////////////

textord/underlin.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ void restore_underlined_blobs( //get chop points
9393
ru_it.add_after_then_move(new BLOBNBOX(new C_BLOB(&left_coutlines)));
9494
}
9595
if (u_line != nullptr) {
96-
if (u_line->cblob() != nullptr)
97-
delete u_line->cblob();
96+
delete u_line->cblob();
9897
delete u_line;
9998
}
10099
}

viewer/scrollview.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,8 @@ void ScrollView::SetEvent(SVEvent* svevent) {
431431
// Place both events into the queue.
432432
mutex_->Lock();
433433
// Delete the old objects..
434-
if (event_table_[specific->type] != nullptr) {
435-
delete event_table_[specific->type]; }
436-
if (event_table_[SVET_ANY] != nullptr) {
437-
delete event_table_[SVET_ANY]; }
434+
delete event_table_[specific->type];
435+
delete event_table_[SVET_ANY];
438436
// ...and put the new ones in the table.
439437
event_table_[specific->type] = specific;
440438
event_table_[SVET_ANY] = any;

wordrec/findseam.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ void Wordrec::choose_best_seam(SeamQueue *seam_queue, const SPLIT *split,
150150
}
151151

152152
if (my_priority < chop_good_split) {
153-
if (seam)
154-
delete seam;
153+
delete seam;
155154
return; /* Made good answer */
156155
}
157156

0 commit comments

Comments
 (0)