mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-06-10 20:23:12 +08:00
Optimize code by replacing init_to_size with resize_no_init
There is no need to initialize memory with a fixed value which is overwritten in the next step. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
bb2348bbbe
commit
3a67ff930e
@ -232,7 +232,7 @@ float compute_reject_threshold(WERD_CHOICE* word) {
|
|||||||
|
|
||||||
int blob_count = word->length();
|
int blob_count = word->length();
|
||||||
GenericVector<float> ratings;
|
GenericVector<float> ratings;
|
||||||
ratings.init_to_size(blob_count, 0.0f);
|
ratings.resize_no_init(blob_count);
|
||||||
for (int i = 0; i < blob_count; ++i) {
|
for (int i = 0; i < blob_count; ++i) {
|
||||||
ratings[i] = word->certainty(i);
|
ratings[i] = word->certainty(i);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ ImageData* ImageData::Build(const char* name, int page_number, const char* lang,
|
|||||||
image_data->page_number_ = page_number;
|
image_data->page_number_ = page_number;
|
||||||
image_data->language_ = lang;
|
image_data->language_ = lang;
|
||||||
// Save the imagedata.
|
// Save the imagedata.
|
||||||
image_data->image_data_.init_to_size(imagedatasize, 0);
|
image_data->image_data_.resize_no_init(imagedatasize);
|
||||||
memcpy(&image_data->image_data_[0], imagedata, imagedatasize);
|
memcpy(&image_data->image_data_[0], imagedata, imagedatasize);
|
||||||
if (!image_data->AddBoxes(box_text)) {
|
if (!image_data->AddBoxes(box_text)) {
|
||||||
if (truth_text == NULL || truth_text[0] == '\0') {
|
if (truth_text == NULL || truth_text[0] == '\0') {
|
||||||
@ -329,7 +329,7 @@ void ImageData::SetPixInternal(Pix* pix, GenericVector<char>* image_data) {
|
|||||||
size_t size;
|
size_t size;
|
||||||
pixWriteMem(&data, &size, pix, IFF_PNG);
|
pixWriteMem(&data, &size, pix, IFF_PNG);
|
||||||
pixDestroy(&pix);
|
pixDestroy(&pix);
|
||||||
image_data->init_to_size(size, 0);
|
image_data->resize_no_init(size);
|
||||||
memcpy(&(*image_data)[0], data, size);
|
memcpy(&(*image_data)[0], data, size);
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ bool TFile::Open(const char* data, int size) {
|
|||||||
}
|
}
|
||||||
is_writing_ = false;
|
is_writing_ = false;
|
||||||
swap_ = false;
|
swap_ = false;
|
||||||
data_->init_to_size(size, 0);
|
data_->resize_no_init(size);
|
||||||
memcpy(&(*data_)[0], data, size);
|
memcpy(&(*data_)[0], data, size);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ bool TFile::Open(FILE* fp, inT64 end_offset) {
|
|||||||
data_ = new GenericVector<char>;
|
data_ = new GenericVector<char>;
|
||||||
data_is_owned_ = true;
|
data_is_owned_ = true;
|
||||||
}
|
}
|
||||||
data_->init_to_size(size, 0);
|
data_->resize_no_init(size);
|
||||||
return static_cast<int>(fread(&(*data_)[0], 1, size, fp)) == size;
|
return static_cast<int>(fread(&(*data_)[0], 1, size, fp)) == size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ bool TessdataManager::LoadMemBuffer(const char *name, const char *data,
|
|||||||
fp.set_swap(swap_);
|
fp.set_swap(swap_);
|
||||||
if (swap_) ReverseN(&num_entries, sizeof(num_entries));
|
if (swap_) ReverseN(&num_entries, sizeof(num_entries));
|
||||||
GenericVector<inT64> offset_table;
|
GenericVector<inT64> offset_table;
|
||||||
offset_table.init_to_size(num_entries, -1);
|
offset_table.resize_no_init(num_entries);
|
||||||
if (fp.FReadEndian(&offset_table[0], sizeof(offset_table[0]), num_entries) !=
|
if (fp.FReadEndian(&offset_table[0], sizeof(offset_table[0]), num_entries) !=
|
||||||
num_entries)
|
num_entries)
|
||||||
return false;
|
return false;
|
||||||
@ -72,7 +72,7 @@ bool TessdataManager::LoadMemBuffer(const char *name, const char *data,
|
|||||||
int j = i + 1;
|
int j = i + 1;
|
||||||
while (j < num_entries && offset_table[j] == -1) ++j;
|
while (j < num_entries && offset_table[j] == -1) ++j;
|
||||||
if (j < num_entries) entry_size = offset_table[j] - offset_table[i];
|
if (j < num_entries) entry_size = offset_table[j] - offset_table[i];
|
||||||
entries_[i].init_to_size(entry_size, 0);
|
entries_[i].resize_no_init(entry_size);
|
||||||
if (fp.FRead(&entries_[i][0], 1, entry_size) != entry_size) return false;
|
if (fp.FRead(&entries_[i][0], 1, entry_size) != entry_size) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ bool TessdataManager::LoadMemBuffer(const char *name, const char *data,
|
|||||||
void TessdataManager::OverwriteEntry(TessdataType type, const char *data,
|
void TessdataManager::OverwriteEntry(TessdataType type, const char *data,
|
||||||
int size) {
|
int size) {
|
||||||
is_loaded_ = true;
|
is_loaded_ = true;
|
||||||
entries_[type].init_to_size(size, 0);
|
entries_[type].resize_no_init(size);
|
||||||
memcpy(&entries_[type][0], data, size);
|
memcpy(&entries_[type][0], data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ bool TFNetwork::Serialize(TFile* fp) const {
|
|||||||
string proto_str;
|
string proto_str;
|
||||||
model_proto_.SerializeToString(&proto_str);
|
model_proto_.SerializeToString(&proto_str);
|
||||||
GenericVector<char> data;
|
GenericVector<char> data;
|
||||||
data.init_to_size(proto_str.size(), 0);
|
data.resize_no_init(proto_str.size());
|
||||||
memcpy(&data[0], proto_str.data(), proto_str.size());
|
memcpy(&data[0], proto_str.data(), proto_str.size());
|
||||||
if (!data.Serialize(fp)) return false;
|
if (!data.Serialize(fp)) return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -150,7 +150,7 @@ bool WeightMatrix::DeSerializeOld(bool training, TFile* fp) {
|
|||||||
if (!wi_.DeSerialize(fp)) return false;
|
if (!wi_.DeSerialize(fp)) return false;
|
||||||
GenericVector<float> old_scales;
|
GenericVector<float> old_scales;
|
||||||
if (!old_scales.DeSerialize(fp)) return false;
|
if (!old_scales.DeSerialize(fp)) return false;
|
||||||
scales_.init_to_size(old_scales.size(), 0.0);
|
scales_.resize_no_init(old_scales.size());
|
||||||
for (int i = 0; i < old_scales.size(); ++i) scales_[i] = old_scales[i];
|
for (int i = 0; i < old_scales.size(); ++i) scales_[i] = old_scales[i];
|
||||||
} else {
|
} else {
|
||||||
if (!float_array.DeSerialize(fp)) return false;
|
if (!float_array.DeSerialize(fp)) return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user