Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary memory allocations #352

Merged
merged 2 commits into from
Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ccutil/genericvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions wordrec/language_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;;
Expand Down
10 changes: 3 additions & 7 deletions wordrec/lm_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down