Skip to content

Commit 5f297dc

Browse files
authored
Merge pull request #3967 from stweil/coverity
Fix a number of performance issues (reported by Coverity Scan)
2 parents 1751fba + a9c1be6 commit 5f297dc

File tree

14 files changed

+19
-19
lines changed

14 files changed

+19
-19
lines changed

src/api/hocrrenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ char *TessBaseAPI::GetHOCRText(ETEXT_DESC *monitor, int page_number) {
412412
<< " id='"
413413
<< "timestep" << page_id << "_" << wcnt << "_" << tcnt
414414
<< "'>";
415-
for (auto conf : timestep) {
415+
for (auto &&conf : timestep) {
416416
hocr_str << "\n <span class='ocrx_cinfo'"
417417
<< " id='"
418418
<< "choice_" << page_id << "_" << wcnt << "_" << ccnt

src/ccmain/control.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ bool Tesseract::SelectGoodDiacriticOutlines(int pass, float certainty_threshold,
11911191
*ok_outlines = best_outlines;
11921192
if (debug_noise_removal) {
11931193
tprintf("%s noise combination ", blob ? "Adding" : "New");
1194-
for (auto best_outline : best_outlines) {
1194+
for (auto &&best_outline : best_outlines) {
11951195
tprintf("%c", best_outline ? 'T' : 'F');
11961196
}
11971197
tprintf(" yields certainty %g, beating target of %g\n", best_cert, target_cert);

src/ccstruct/fontinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool FontInfoTable::DeSerialize(TFile *fp) {
6767
bool FontInfoTable::SetContainsFontProperties(int font_id,
6868
const std::vector<ScoredFont> &font_set) const {
6969
uint32_t properties = at(font_id).properties;
70-
for (auto f : font_set) {
70+
for (auto &&f : font_set) {
7171
if (at(f.fontinfo_id).properties == properties) {
7272
return true;
7373
}

src/ccstruct/points.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ class TESS_API FCOORD {
269269
bool normalise();
270270

271271
/// test equality
272-
bool operator==(const FCOORD &other) {
272+
bool operator==(const FCOORD &other) const {
273273
return xcoord == other.xcoord && ycoord == other.ycoord;
274274
}
275275
/// test inequality
276-
bool operator!=(const FCOORD &other) {
276+
bool operator!=(const FCOORD &other) const {
277277
return xcoord != other.xcoord || ycoord != other.ycoord;
278278
}
279279
/// rotate 90 deg anti

src/ccutil/params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class StringParam : public Param {
253253
bool empty() const {
254254
return value_.empty();
255255
}
256-
bool operator==(const std::string &other) {
256+
bool operator==(const std::string &other) const {
257257
return value_ == other;
258258
}
259259
void operator=(const std::string &value) {

src/ccutil/serialis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class TESS_API TFile {
157157
return false;
158158
} else if constexpr (std::is_same<T, std::string>::value) {
159159
// Serialize strings.
160-
for (auto string : data) {
160+
for (auto &&string : data) {
161161
if (!Serialize(string)) {
162162
return false;
163163
}

src/classify/adaptmatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ void Classify::MasterMatcher(INT_TEMPLATES_STRUCT *templates, int16_t num_featur
10791079
int top = blob_box.top();
10801080
int bottom = blob_box.bottom();
10811081
UnicharRating int_result;
1082-
for (auto result : results) {
1082+
for (auto &&result : results) {
10831083
CLASS_ID class_id = result.Class;
10841084
BIT_VECTOR protos = classes != nullptr ? classes[class_id]->PermProtos : AllProtosOn;
10851085
BIT_VECTOR configs = classes != nullptr ? classes[class_id]->PermConfigs : AllConfigsOn;

src/classify/shapeclassifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void ShapeClassifier::UnicharPrintResults(const char *context,
174174
GetUnicharset().id_to_unichar(result.unichar_id));
175175
if (!result.fonts.empty()) {
176176
tprintf(" Font Vector:");
177-
for (auto font : result.fonts) {
177+
for (auto &&font : result.fonts) {
178178
tprintf(" %d", font.fontinfo_id);
179179
}
180180
}

src/dict/dawg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ struct DawgPosition {
361361
dawg_index(dawg_idx),
362362
punc_index(punc_idx),
363363
back_to_punc(backtopunc) {}
364-
bool operator==(const DawgPosition &other) {
364+
bool operator==(const DawgPosition &other) const {
365365
return dawg_index == other.dawg_index && dawg_ref == other.dawg_ref &&
366366
punc_index == other.punc_index && punc_ref == other.punc_ref &&
367367
back_to_punc == other.back_to_punc;
@@ -382,7 +382,7 @@ class DawgPositionVector : public std::vector<DawgPosition> {
382382
/// true otherwise.
383383
inline bool add_unique(const DawgPosition &new_pos, bool debug,
384384
const char *debug_msg) {
385-
for (auto position : *this) {
385+
for (auto &&position : *this) {
386386
if (position == new_pos) {
387387
return false;
388388
}

src/lstm/networkio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void NetworkIO::FromPixes(const StaticShape &shape, const std::vector<Image> &pi
173173
int target_height = shape.height();
174174
int target_width = shape.width();
175175
std::vector<std::pair<int, int>> h_w_pairs;
176-
for (auto pix : pixes) {
176+
for (auto &&pix : pixes) {
177177
Image var_pix = pix;
178178
int width = pixGetWidth(var_pix);
179179
if (target_width != 0) {

0 commit comments

Comments
 (0)