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

Remove unnecessary assignment and assertions #4313

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
17 changes: 7 additions & 10 deletions src/ccmain/ltrresultiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ float LTRResultIterator::Confidence(PageIteratorLevel level) const {
float mean_certainty = 0.0f;
int certainty_count = 0;
PAGE_RES_IT res_it(*it_);
WERD_CHOICE *best_choice = res_it.word()->best_choice;
ASSERT_HOST(best_choice != nullptr);
WERD_CHOICE *best_choice;
switch (level) {
case RIL_BLOCK:
do {
best_choice = res_it.word()->best_choice;
ASSERT_HOST(best_choice != nullptr);
mean_certainty += best_choice->certainty();
++certainty_count;
res_it.forward();
Expand All @@ -114,7 +112,6 @@ float LTRResultIterator::Confidence(PageIteratorLevel level) const {
case RIL_PARA:
do {
best_choice = res_it.word()->best_choice;
ASSERT_HOST(best_choice != nullptr);
mean_certainty += best_choice->certainty();
++certainty_count;
res_it.forward();
Expand All @@ -124,19 +121,20 @@ float LTRResultIterator::Confidence(PageIteratorLevel level) const {
case RIL_TEXTLINE:
do {
best_choice = res_it.word()->best_choice;
ASSERT_HOST(best_choice != nullptr);
mean_certainty += best_choice->certainty();
++certainty_count;
res_it.forward();
} while (res_it.row() == res_it.prev_row());
break;
case RIL_WORD:
mean_certainty += best_choice->certainty();
++certainty_count;
best_choice = res_it.word()->best_choice;
mean_certainty = best_choice->certainty();
certainty_count = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't change behavor?

++certainty_count; vs certainty_count = 1;

Copy link
Contributor Author

@stweil stweil Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial value 0 and a single increment gives value 1. There is no loop around it, only a switch statement.

break;
case RIL_SYMBOL:
mean_certainty += best_choice->certainty(blob_index_);
++certainty_count;
best_choice = res_it.word()->best_choice;
mean_certainty = best_choice->certainty(blob_index_);
certainty_count = 1;
}
if (certainty_count > 0) {
mean_certainty /= certainty_count;
Expand Down Expand Up @@ -320,7 +318,6 @@ char *LTRResultIterator::WordNormedUTF8Text() const {
std::string ocr_text;
WERD_CHOICE *best_choice = it_->word()->best_choice;
const UNICHARSET *unicharset = it_->word()->uch_set;
ASSERT_HOST(best_choice != nullptr);
for (unsigned i = 0; i < best_choice->length(); ++i) {
ocr_text += unicharset->get_normed_unichar(best_choice->unichar_id(i));
}
Expand Down
Loading