From b6db68f083aaece9f74e4a3162acedd41db2af3a Mon Sep 17 00:00:00 2001 From: Philipp Nordhus Date: Fri, 17 Jun 2016 01:17:04 +0200 Subject: [PATCH 1/2] Remove indirection in LanguageModelDawgInfo --- wordrec/language_model.cpp | 6 +++--- wordrec/lm_state.h | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/wordrec/language_model.cpp b/wordrec/language_model.cpp index f0e3be66f2..84c368434d 100644 --- a/wordrec/language_model.cpp +++ b/wordrec/language_model.cpp @@ -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;; diff --git a/wordrec/lm_state.h b/wordrec/lm_state.h index 623bbb5e7f..86319ae85b 100644 --- a/wordrec/lm_state.h +++ b/wordrec/lm_state.h @@ -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; }; From 907de5995f698e2a01da25fa09f8cadaf31a095f Mon Sep 17 00:00:00 2001 From: Philipp Nordhus Date: Fri, 17 Jun 2016 22:28:55 +0200 Subject: [PATCH 2/2] Do not allocate in GenericVector default ctor --- ccutil/genericvector.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ccutil/genericvector.h b/ccutil/genericvector.h index d867d8929b..00c1fe63d3 100644 --- a/ccutil/genericvector.h +++ b/ccutil/genericvector.h @@ -37,9 +37,9 @@ template 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);