Skip to content

Commit a9c1be6

Browse files
committed
Fix a number of performance issues (reported by Coverity Scan)
Coverity Scan reports "Unnecessary object copies can affect performance" and suggests using the auto keyword with an &. Signed-off-by: Stefan Weil <[email protected]>
1 parent 4c0051d commit a9c1be6

File tree

12 files changed

+14
-14
lines changed

12 files changed

+14
-14
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/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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) {

src/lstm/recodebeam.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ void RecodeBeamSearch::PrintBeam2(bool uids, int num_outputs,
341341
// fill the topology with depths first
342342
for (int step = beam.size() - 1; step >= 0; --step) {
343343
std::vector<tesseract::RecodePair> &heaps = beam.at(step)->beams_->heap();
344-
for (auto node : heaps) {
344+
for (auto &&node : heaps) {
345345
int backtracker = 0;
346346
const RecodeNode *curr = &node.data();
347347
while (curr != nullptr && !visited.count(curr)) {
@@ -426,7 +426,7 @@ void RecodeBeamSearch::extractSymbolChoices(const UNICHARSET *unicharset) {
426426
std::vector<const RecodeNode *> best_nodes;
427427
std::vector<const RecodeNode *> best;
428428
// Scan the segmented node chain for valid unichar ids.
429-
for (auto entry : heaps) {
429+
for (auto &&entry : heaps) {
430430
bool validChar = false;
431431
int backcounter = 0;
432432
const RecodeNode *node = &entry.data();

src/training/pango/pango_font_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ int FontUtils::FontScore(const std::unordered_map<char32, int64_t> &ch_map,
591591
}
592592
*raw_score = 0;
593593
int ok_chars = 0;
594-
for (auto it : ch_map) {
594+
for (auto &&it : ch_map) {
595595
bool covered =
596596
(coverage != nullptr) && (IsWhitespace(it.first) ||
597597
(pango_coverage_get(coverage, it.first) == PANGO_COVERAGE_EXACT));

0 commit comments

Comments
 (0)