Skip to content

Commit 85e3779

Browse files
committed
Simplify delete operations
It is not necessary to check for null pointers. Signed-off-by: Stefan Weil <[email protected]>
1 parent 6158f7e commit 85e3779

15 files changed

+23
-40
lines changed

api/baseapi.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,7 @@ int TessBaseAPI::Recognize(ETEXT_DESC* monitor) {
830830
return -1;
831831
if (FindLines() != 0)
832832
return -1;
833-
if (page_res_ != NULL)
834-
delete page_res_;
833+
delete page_res_;
835834
if (block_list_->empty()) {
836835
page_res_ = new PAGE_RES(false, block_list_,
837836
&tesseract_->prev_word_best_choice_);

api/baseapi.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ class TESS_API TessBaseAPI {
373373
* delete it when it it is replaced or the API is destructed.
374374
*/
375375
void SetThresholder(ImageThresholder* thresholder) {
376-
if (thresholder_ != NULL)
377-
delete thresholder_;
376+
delete thresholder_;
378377
thresholder_ = thresholder;
379378
ClearResults();
380379
}

ccmain/pageiterator.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const PageIterator& PageIterator::operator=(const PageIterator& src) {
8787
rect_top_ = src.rect_top_;
8888
rect_width_ = src.rect_width_;
8989
rect_height_ = src.rect_height_;
90-
if (it_ != NULL) delete it_;
90+
delete it_;
9191
it_ = new PAGE_RES_IT(*src.it_);
9292
BeginWord(src.blob_index_);
9393
return *this;
@@ -597,10 +597,8 @@ void PageIterator::BeginWord(int offset) {
597597
}
598598
word_ = NULL;
599599
// We will be iterating the box_word.
600-
if (cblob_it_ != NULL) {
601-
delete cblob_it_;
602-
cblob_it_ = NULL;
603-
}
600+
delete cblob_it_;
601+
cblob_it_ = NULL;
604602
} else {
605603
// No recognition yet, so a "symbol" is a cblob.
606604
word_ = word_res->word;

ccmain/pgedit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ ScrollView* bln_word_window_handle() { // return handle
191191
*/
192192

193193
void build_image_window(int width, int height) {
194-
if (image_win != NULL) { delete image_win; }
194+
delete image_win;
195195
image_win = new ScrollView(editor_image_win_name.string(),
196196
editor_image_xpos, editor_image_ypos,
197197
width + 1,

ccstruct/pdblock.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class PDBLK {
5151

5252
/// destructor
5353
~PDBLK() {
54-
if (hand_poly) delete hand_poly;
54+
delete hand_poly;
5555
}
5656

5757
POLY_BLOCK *poly_block() const { return hand_poly; }

ccutil/hashfn.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ template<class T> class SmartPtr {
6363
return ptr_;
6464
}
6565
void reset(T* ptr) {
66-
if (ptr_ != NULL) delete ptr_;
66+
delete ptr_;
6767
ptr_ = ptr;
6868
}
6969
bool operator==(const T* ptr) const {

classify/trainingsample.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void TrainingSample::ExtractCharDesc(int int_feature_type,
209209
int geo_type,
210210
CHAR_DESC_STRUCT* char_desc) {
211211
// Extract the INT features.
212-
if (features_ != NULL) delete [] features_;
212+
delete [] features_;
213213
FEATURE_SET_STRUCT* char_features = char_desc->FeatureSets[int_feature_type];
214214
if (char_features == NULL) {
215215
tprintf("Error: no features to train on of type %s\n",
@@ -230,7 +230,7 @@ void TrainingSample::ExtractCharDesc(int int_feature_type,
230230
}
231231
}
232232
// Extract the Micro features.
233-
if (micro_features_ != NULL) delete [] micro_features_;
233+
delete [] micro_features_;
234234
char_features = char_desc->FeatureSets[micro_type];
235235
if (char_features == NULL) {
236236
tprintf("Error: no features to train on of type %s\n",

classify/trainingsampleset.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,8 @@ bool TrainingSampleSet::DeSerialize(bool swap, FILE* fp) {
9696
num_raw_samples_ = samples_.size();
9797
if (!unicharset_.load_from_file(fp)) return false;
9898
if (!font_id_map_.DeSerialize(swap, fp)) return false;
99-
if (font_class_array_ != NULL) {
100-
delete font_class_array_;
101-
font_class_array_ = NULL;
102-
}
99+
delete font_class_array_;
100+
font_class_array_ = NULL;
103101
inT8 not_null;
104102
if (fread(&not_null, sizeof(not_null), 1, fp) != 1) return false;
105103
if (not_null) {

cube/char_samp_set.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ void CharSampSet::Cleanup() {
4040
// only free samples if owned by class
4141
if (own_samples_ == true) {
4242
for (int samp_idx = 0; samp_idx < cnt_; samp_idx++) {
43-
if (samp_buff_[samp_idx] != NULL) {
44-
delete samp_buff_[samp_idx];
45-
}
43+
delete samp_buff_[samp_idx];
4644
}
4745
}
4846
delete []samp_buff_;

cube/search_column.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ SearchNode *SearchColumn::AddNode(LangModEdge *edge, int reco_cost,
195195
}
196196

197197
// free the edge
198-
if (edge != NULL) {
199-
delete edge;
200-
}
198+
delete edge;
201199
}
202200

203201
// update Min and Max Costs

dict/dict.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Dict::Dict(CCUtil *ccutil)
191191

192192
Dict::~Dict() {
193193
End();
194-
if (hyphen_word_ != NULL) delete hyphen_word_;
194+
delete hyphen_word_;
195195
if (output_ambig_words_file_ != NULL) fclose(output_ambig_words_file_);
196196
}
197197

@@ -360,10 +360,8 @@ void Dict::End() {
360360
dawgs_.clear();
361361
successors_.clear();
362362
document_words_ = NULL;
363-
if (pending_words_ != NULL) {
364-
delete pending_words_;
365-
pending_words_ = NULL;
366-
}
363+
delete pending_words_;
364+
pending_words_ = NULL;
367365
}
368366

369367
// Returns true if in light of the current state unichar_id is allowed

textord/fpchop.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ void split_to_blob( //split the blob
259259
pitch_error,
260260
left_coutlines,
261261
right_coutlines);
262-
if (blob != NULL)
263-
delete blob; //free it
262+
263+
delete blob;
264264
}
265265

266266
/**********************************************************************

textord/makerow.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ void vigorous_noise_removal(TO_BLOCK* block) {
507507
continue; // Looks OK.
508508
}
509509
// It might be noise so get rid of it.
510-
if (blob->cblob() != NULL)
511-
delete blob->cblob();
510+
delete blob->cblob();
512511
delete b_it.extract();
513512
} else {
514513
prev = blob;

wordrec/chopper.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,7 @@ int Wordrec::select_blob_to_split(
568568

569569
for (x = 0; x < blob_choices.size(); ++x) {
570570
if (blob_choices[x] == NULL) {
571-
if (fragments != NULL) {
572-
delete[] fragments;
573-
}
571+
delete[] fragments;
574572
return x;
575573
} else {
576574
blob_choice = blob_choices[x];
@@ -614,9 +612,7 @@ int Wordrec::select_blob_to_split(
614612
}
615613
}
616614
}
617-
if (fragments != NULL) {
618-
delete[] fragments;
619-
}
615+
delete[] fragments;
620616
// TODO(daria): maybe a threshold of badness for
621617
// worst_near_fragment would be useful.
622618
return worst_index_near_fragment != -1 ?

wordrec/language_model.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ float LanguageModel::ComputeNgramCost(const char *unichar,
988988
unichar, context_ptr, CertaintyScore(certainty)/denom, prob,
989989
ngram_and_classifier_cost);
990990
}
991-
if (modified_context != NULL) delete[] modified_context;
991+
delete[] modified_context;
992992
return ngram_and_classifier_cost;
993993
}
994994

0 commit comments

Comments
 (0)