ScanTailor-Advanced / scantailor-advanced

ScanTailor Advanced is the version that merges the features of the ScanTailor Featured and ScanTailor Enhanced versions, brings new ones and fixes.
GNU General Public License v3.0
194 stars 8 forks source link

Compilation warning: range copy in loop #34

Closed eudoxos closed 1 year ago

eudoxos commented 1 year ago

Hi, thank you for you work on the fork, nice to see compilation almost warning-free. I don't know the code so well to say whether the following warning (current git version, gcc 11.3.0) is spurious (and a copy is intended) or it could be replaced with the references. So just dropping it here for your consideration.

https://github.com/vigri/scantailor-advanced/blob/d799b8a0a9e5ea2851e6c9f21476794fa24de3de/src/core/filters/select_content/ContentBoxFinder.cpp#L771

In static member function ‘static imageproc::BinaryImage select_content::ContentBoxFinder::estimateTextMask(const imageproc::BinaryImage&, const imageproc::BinaryImage&, DebugImages*)’:
scantailor-advanced-vigri/src/core/filters/select_content/ContentBoxFinder.cpp:771:22: warning: loop variable ‘range’ creates a copy from type ‘const Range’ {aka ‘const std::pair<const int*, const int*>’} [-Wrange-loop-construct]
  771 |     for (const Range range : ranges) {
      |                      ^~~~~
scantailor-advanced-vigri/src/core/filters/select_content/ContentBoxFinder.cpp:771:22: note: use reference type to prevent copying
  771 |     for (const Range range : ranges) {
      |                      ^~~~~
      |                      &
trufanov-nok commented 1 year ago

it should be for (const Range& range : qAsConst(ranges)) {

ghost commented 1 year ago

Thanks @trufanov-nok That worked like a charm. I'll PR it.