Skip to content

Commit

Permalink
Merge pull request #3967 from stweil/coverity
Browse files Browse the repository at this point in the history
Fix a number of performance issues (reported by Coverity Scan)
  • Loading branch information
zdenop committed Nov 21, 2022
2 parents 1751fba + a9c1be6 commit 5f297dc
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/api/hocrrenderer.cpp
Expand Up @@ -412,7 +412,7 @@ char *TessBaseAPI::GetHOCRText(ETEXT_DESC *monitor, int page_number) {
<< " id='"
<< "timestep" << page_id << "_" << wcnt << "_" << tcnt
<< "'>";
for (auto conf : timestep) {
for (auto &&conf : timestep) {
hocr_str << "\n <span class='ocrx_cinfo'"
<< " id='"
<< "choice_" << page_id << "_" << wcnt << "_" << ccnt
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/control.cpp
Expand Up @@ -1191,7 +1191,7 @@ bool Tesseract::SelectGoodDiacriticOutlines(int pass, float certainty_threshold,
*ok_outlines = best_outlines;
if (debug_noise_removal) {
tprintf("%s noise combination ", blob ? "Adding" : "New");
for (auto best_outline : best_outlines) {
for (auto &&best_outline : best_outlines) {
tprintf("%c", best_outline ? 'T' : 'F');
}
tprintf(" yields certainty %g, beating target of %g\n", best_cert, target_cert);
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/fontinfo.cpp
Expand Up @@ -67,7 +67,7 @@ bool FontInfoTable::DeSerialize(TFile *fp) {
bool FontInfoTable::SetContainsFontProperties(int font_id,
const std::vector<ScoredFont> &font_set) const {
uint32_t properties = at(font_id).properties;
for (auto f : font_set) {
for (auto &&f : font_set) {
if (at(f.fontinfo_id).properties == properties) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ccstruct/points.h
Expand Up @@ -269,11 +269,11 @@ class TESS_API FCOORD {
bool normalise();

/// test equality
bool operator==(const FCOORD &other) {
bool operator==(const FCOORD &other) const {
return xcoord == other.xcoord && ycoord == other.ycoord;
}
/// test inequality
bool operator!=(const FCOORD &other) {
bool operator!=(const FCOORD &other) const {
return xcoord != other.xcoord || ycoord != other.ycoord;
}
/// rotate 90 deg anti
Expand Down
2 changes: 1 addition & 1 deletion src/ccutil/params.h
Expand Up @@ -253,7 +253,7 @@ class StringParam : public Param {
bool empty() const {
return value_.empty();
}
bool operator==(const std::string &other) {
bool operator==(const std::string &other) const {
return value_ == other;
}
void operator=(const std::string &value) {
Expand Down
2 changes: 1 addition & 1 deletion src/ccutil/serialis.h
Expand Up @@ -157,7 +157,7 @@ class TESS_API TFile {
return false;
} else if constexpr (std::is_same<T, std::string>::value) {
// Serialize strings.
for (auto string : data) {
for (auto &&string : data) {
if (!Serialize(string)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/classify/adaptmatch.cpp
Expand Up @@ -1079,7 +1079,7 @@ void Classify::MasterMatcher(INT_TEMPLATES_STRUCT *templates, int16_t num_featur
int top = blob_box.top();
int bottom = blob_box.bottom();
UnicharRating int_result;
for (auto result : results) {
for (auto &&result : results) {
CLASS_ID class_id = result.Class;
BIT_VECTOR protos = classes != nullptr ? classes[class_id]->PermProtos : AllProtosOn;
BIT_VECTOR configs = classes != nullptr ? classes[class_id]->PermConfigs : AllConfigsOn;
Expand Down
2 changes: 1 addition & 1 deletion src/classify/shapeclassifier.cpp
Expand Up @@ -174,7 +174,7 @@ void ShapeClassifier::UnicharPrintResults(const char *context,
GetUnicharset().id_to_unichar(result.unichar_id));
if (!result.fonts.empty()) {
tprintf(" Font Vector:");
for (auto font : result.fonts) {
for (auto &&font : result.fonts) {
tprintf(" %d", font.fontinfo_id);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/dict/dawg.h
Expand Up @@ -361,7 +361,7 @@ struct DawgPosition {
dawg_index(dawg_idx),
punc_index(punc_idx),
back_to_punc(backtopunc) {}
bool operator==(const DawgPosition &other) {
bool operator==(const DawgPosition &other) const {
return dawg_index == other.dawg_index && dawg_ref == other.dawg_ref &&
punc_index == other.punc_index && punc_ref == other.punc_ref &&
back_to_punc == other.back_to_punc;
Expand All @@ -382,7 +382,7 @@ class DawgPositionVector : public std::vector<DawgPosition> {
/// true otherwise.
inline bool add_unique(const DawgPosition &new_pos, bool debug,
const char *debug_msg) {
for (auto position : *this) {
for (auto &&position : *this) {
if (position == new_pos) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lstm/networkio.cpp
Expand Up @@ -173,7 +173,7 @@ void NetworkIO::FromPixes(const StaticShape &shape, const std::vector<Image> &pi
int target_height = shape.height();
int target_width = shape.width();
std::vector<std::pair<int, int>> h_w_pairs;
for (auto pix : pixes) {
for (auto &&pix : pixes) {
Image var_pix = pix;
int width = pixGetWidth(var_pix);
if (target_width != 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/lstm/recodebeam.cpp
Expand Up @@ -322,7 +322,7 @@ void RecodeBeamSearch::ExtractBestPathAsWords(const TBOX &line_box,
}

struct greater_than {
inline bool operator()(const RecodeNode *&node1, const RecodeNode *&node2) {
inline bool operator()(const RecodeNode *&node1, const RecodeNode *&node2) const {
return (node1->score > node2->score);
}
};
Expand All @@ -341,7 +341,7 @@ void RecodeBeamSearch::PrintBeam2(bool uids, int num_outputs,
// fill the topology with depths first
for (int step = beam.size() - 1; step >= 0; --step) {
std::vector<tesseract::RecodePair> &heaps = beam.at(step)->beams_->heap();
for (auto node : heaps) {
for (auto &&node : heaps) {
int backtracker = 0;
const RecodeNode *curr = &node.data();
while (curr != nullptr && !visited.count(curr)) {
Expand Down Expand Up @@ -426,7 +426,7 @@ void RecodeBeamSearch::extractSymbolChoices(const UNICHARSET *unicharset) {
std::vector<const RecodeNode *> best_nodes;
std::vector<const RecodeNode *> best;
// Scan the segmented node chain for valid unichar ids.
for (auto entry : heaps) {
for (auto &&entry : heaps) {
bool validChar = false;
int backcounter = 0;
const RecodeNode *node = &entry.data();
Expand Down
2 changes: 1 addition & 1 deletion src/training/pango/pango_font_info.cpp
Expand Up @@ -591,7 +591,7 @@ int FontUtils::FontScore(const std::unordered_map<char32, int64_t> &ch_map,
}
*raw_score = 0;
int ok_chars = 0;
for (auto it : ch_map) {
for (auto &&it : ch_map) {
bool covered =
(coverage != nullptr) && (IsWhitespace(it.first) ||
(pango_coverage_get(coverage, it.first) == PANGO_COVERAGE_EXACT));
Expand Down
2 changes: 1 addition & 1 deletion src/wordrec/chopper.cpp
Expand Up @@ -283,7 +283,7 @@ SEAM *Wordrec::chop_overlapping_blob(const std::vector<TBOX> &boxes, bool italic

bool almost_equal_box = false;
int num_overlap = 0;
for (auto boxe : boxes) {
for (auto &&boxe : boxes) {
if (original_box.overlap_fraction(boxe) > 0.125) {
num_overlap++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/wordrec/lm_pain_points.cpp
Expand Up @@ -130,7 +130,7 @@ void LMPainPoints::GenerateFromAmbigs(const DANGERR &fixpt, ViterbiStateEntry *v
WERD_RES *word_res) {
// Begins and ends in DANGERR vector now record the blob indices as used
// by the ratings matrix.
for (auto danger : fixpt) {
for (auto &&danger : fixpt) {
// Only use dangerous ambiguities.
if (danger.dangerous) {
GeneratePainPoint(danger.begin, danger.end - 1, LM_PPTYPE_AMBIG, vse->cost, true,
Expand Down Expand Up @@ -203,7 +203,7 @@ bool LMPainPoints::GeneratePainPoint(int col, int row, LMPainPointsType pp_type,
void LMPainPoints::RemapForSplit(int index) {
for (auto &pain_points_heap : pain_points_heaps_) {
std::vector<MatrixCoordPair> &heap = pain_points_heap.heap();
for (auto entry : heap) {
for (auto &&entry : heap) {
entry.data().MapForSplit(index);
}
}
Expand Down

0 comments on commit 5f297dc

Please sign in to comment.