mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-18 06:30:14 +08:00
Merge pull request #352 from pnordhus/reduce_mallocs
Avoid unnecessary memory allocations
This commit is contained in:
commit
fd3f8f9b2d
@ -37,9 +37,9 @@
|
||||
template <typename T>
|
||||
class GenericVector {
|
||||
public:
|
||||
GenericVector() {
|
||||
init(kDefaultVectorSize);
|
||||
}
|
||||
GenericVector() : size_used_(0), size_reserved_(0), data_(NULL),
|
||||
clear_cb_(NULL), compare_cb_(NULL) {}
|
||||
|
||||
GenericVector(int size, T init_val) {
|
||||
init(size);
|
||||
init_to_size(size, init_val);
|
||||
|
@ -796,7 +796,7 @@ LanguageModelDawgInfo *LanguageModel::GenerateDawgInfo(
|
||||
dawg_args_->permuter = NO_PERM;
|
||||
} else {
|
||||
if (parent_vse->dawg_info == NULL) return NULL; // not a dict word path
|
||||
dawg_args_->active_dawgs = parent_vse->dawg_info->active_dawgs;
|
||||
dawg_args_->active_dawgs = &parent_vse->dawg_info->active_dawgs;
|
||||
dawg_args_->permuter = parent_vse->dawg_info->permuter;
|
||||
}
|
||||
|
||||
@ -822,8 +822,8 @@ LanguageModelDawgInfo *LanguageModel::GenerateDawgInfo(
|
||||
int i;
|
||||
// Check a that the path terminated before the current character is a word.
|
||||
bool has_word_ending = false;
|
||||
for (i = 0; i < parent_vse->dawg_info->active_dawgs->size(); ++i) {
|
||||
const DawgPosition &pos = (*parent_vse->dawg_info->active_dawgs)[i];
|
||||
for (i = 0; i < parent_vse->dawg_info->active_dawgs.size(); ++i) {
|
||||
const DawgPosition &pos = parent_vse->dawg_info->active_dawgs[i];
|
||||
const Dawg *pdawg = pos.dawg_index < 0
|
||||
? NULL : dict_->GetDawg(pos.dawg_index);
|
||||
if (pdawg == NULL || pos.back_to_punc) continue;;
|
||||
|
@ -59,13 +59,9 @@ typedef unsigned char LanguageModelFlagsType;
|
||||
/// component. It stores the set of active dawgs in which the sequence of
|
||||
/// letters on a path can be found.
|
||||
struct LanguageModelDawgInfo {
|
||||
LanguageModelDawgInfo(DawgPositionVector *a, PermuterType pt) : permuter(pt) {
|
||||
active_dawgs = new DawgPositionVector(*a);
|
||||
}
|
||||
~LanguageModelDawgInfo() {
|
||||
delete active_dawgs;
|
||||
}
|
||||
DawgPositionVector *active_dawgs;
|
||||
LanguageModelDawgInfo(const DawgPositionVector *a, PermuterType pt)
|
||||
: active_dawgs(*a), permuter(pt) {}
|
||||
DawgPositionVector active_dawgs;
|
||||
PermuterType permuter;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user