Skip to content

Commit

Permalink
Merge pull request #857 from stweil/new_delete
Browse files Browse the repository at this point in the history
Avoid unnecessary new / delete code
  • Loading branch information
zdenop authored May 1, 2017
2 parents fd3f8f9 + 6d19e7c commit 6e80812
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 54 deletions.
54 changes: 18 additions & 36 deletions api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2051,18 +2051,12 @@ void TessBaseAPI::Clear() {
*/
void TessBaseAPI::End() {
Clear();
if (thresholder_ != NULL) {
delete thresholder_;
thresholder_ = NULL;
}
if (page_res_ != NULL) {
delete page_res_;
page_res_ = NULL;
}
if (block_list_ != NULL) {
delete block_list_;
block_list_ = NULL;
}
delete thresholder_;
thresholder_ = NULL;
delete page_res_;
page_res_ = NULL;
delete block_list_;
block_list_ = NULL;
if (paragraph_models_ != NULL) {
paragraph_models_->delete_data_pointers();
delete paragraph_models_;
Expand All @@ -2074,30 +2068,18 @@ void TessBaseAPI::End() {
osd_tesseract_ = NULL;
tesseract_ = NULL;
}
if (osd_tesseract_ != NULL) {
delete osd_tesseract_;
osd_tesseract_ = NULL;
}
if (equ_detect_ != NULL) {
delete equ_detect_;
equ_detect_ = NULL;
}
if (input_file_ != NULL) {
delete input_file_;
input_file_ = NULL;
}
if (output_file_ != NULL) {
delete output_file_;
output_file_ = NULL;
}
if (datapath_ != NULL) {
delete datapath_;
datapath_ = NULL;
}
if (language_ != NULL) {
delete language_;
language_ = NULL;
}
delete osd_tesseract_;
osd_tesseract_ = NULL;
delete equ_detect_;
equ_detect_ = NULL;
delete input_file_;
input_file_ = NULL;
delete output_file_;
output_file_ = NULL;
delete datapath_;
datapath_ = NULL;
delete language_;
language_ = NULL;
}

// Clear any library-level memory caches.
Expand Down
5 changes: 1 addition & 4 deletions ccstruct/statistc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ void STATS::clear() { // clear out buckets
* Destructor for a stats class.
**********************************************************************/
STATS::~STATS () {
if (buckets_ != NULL) {
delete [] buckets_;
buckets_ = NULL;
}
delete [] buckets_;
}

/**********************************************************************
Expand Down
5 changes: 0 additions & 5 deletions classify/classify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,13 @@ Classify::Classify()
learn_debug_win_ = NULL;
learn_fragmented_word_debug_win_ = NULL;
learn_fragments_debug_win_ = NULL;

CharNormCutoffs = new uinT16[MAX_NUM_CLASSES];
BaselineCutoffs = new uinT16[MAX_NUM_CLASSES];
}

Classify::~Classify() {
EndAdaptiveClassifier();
delete learn_debug_win_;
delete learn_fragmented_word_debug_win_;
delete learn_fragments_debug_win_;
delete[] CharNormCutoffs;
delete[] BaselineCutoffs;
}


Expand Down
4 changes: 2 additions & 2 deletions classify/classify.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ class Classify : public CCStruct {
// value in the adaptive classifier. Both are indexed by unichar_id.
// shapetable_cutoffs_ provides a similar value for each shape in the
// shape_table_
uinT16* CharNormCutoffs;
uinT16* BaselineCutoffs;
uinT16 CharNormCutoffs[MAX_NUM_CLASSES];
uinT16 BaselineCutoffs[MAX_NUM_CLASSES];
GenericVector<uinT16> shapetable_cutoffs_;
ScrollView* learn_debug_win_;
ScrollView* learn_fragmented_word_debug_win_;
Expand Down
10 changes: 4 additions & 6 deletions viewer/svutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ void SVSemaphore::Wait() {

// Place a message in the message buffer (and flush it).
void SVNetwork::Send(const char* msg) {
mutex_send_->Lock();
mutex_send_.Lock();
msg_buffer_out_.append(msg);
mutex_send_->Unlock();
mutex_send_.Unlock();
}

// Send the whole buffer.
void SVNetwork::Flush() {
mutex_send_->Lock();
mutex_send_.Lock();
while (!msg_buffer_out_.empty()) {
int i = send(stream_, msg_buffer_out_.c_str(), msg_buffer_out_.length(), 0);
msg_buffer_out_.erase(0, i);
}
mutex_send_->Unlock();
mutex_send_.Unlock();
}

// Receive a message from the server.
Expand Down Expand Up @@ -387,7 +387,6 @@ static int GetAddrInfo(const char* hostname, int port,

// Set up a connection to a ScrollView on hostname:port.
SVNetwork::SVNetwork(const char* hostname, int port) {
mutex_send_ = new SVMutex();
msg_buffer_in_ = new char[kMaxMsgSize + 1];
msg_buffer_in_[0] = '\0';

Expand Down Expand Up @@ -448,7 +447,6 @@ SVNetwork::SVNetwork(const char* hostname, int port) {

SVNetwork::~SVNetwork() {
delete[] msg_buffer_in_;
delete mutex_send_;
}

#endif // GRAPHICS_DISABLED
2 changes: 1 addition & 1 deletion viewer/svutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SVNetwork {

private:
/// The mutex for access to Send() and Flush().
SVMutex* mutex_send_;
SVMutex mutex_send_;
/// The actual stream_ to the server.
int stream_;
/// Stores the last received message-chunk from the server.
Expand Down

0 comments on commit 6e80812

Please sign in to comment.