From c8e6ce304f8f113d334227c6fcec3d5f696d1c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 16 Oct 2018 21:09:26 +0200 Subject: [PATCH] Catch exceptions by const-reference Exceptions caught by value incur needless cost in C++, most of them can be caught by const-reference, especially as nearly none are actually used. This could allow compiler generate a slightly more efficient code. --- modules/core/src/copy.cpp | 2 +- modules/core/test/test_ds.cpp | 10 +++++----- modules/imgproc/src/canny.cpp | 4 ++-- modules/imgproc/src/deriv.cpp | 4 ++-- modules/imgproc/src/morph.cpp | 2 +- modules/imgproc/src/resize.cpp | 6 +++--- modules/imgproc/src/smooth.cpp | 10 +++++----- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index 98ab15d4ca..7fb850ee38 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -729,7 +729,7 @@ static bool ipp_flip(Mat &src, Mat &dst, int flip_mode) CV_INSTRUMENT_FUN_IPP(::ipp::iwiMirror, iwSrc, iwDst, ippMode); } - catch(::ipp::IwException) + catch(const ::ipp::IwException &) { return false; } diff --git a/modules/core/test/test_ds.cpp b/modules/core/test/test_ds.cpp index 3a1a00b8b6..64d54c5966 100644 --- a/modules/core/test/test_ds.cpp +++ b/modules/core/test/test_ds.cpp @@ -1032,7 +1032,7 @@ void Core_SeqBaseTest::run( int ) cvClearMemStorage( storage ); } } - catch(int) + catch(const int &) { } } @@ -1200,7 +1200,7 @@ void Core_SeqSortInvTest::run( int ) storage.release(); } } - catch (int) + catch (const int &) { } } @@ -1416,7 +1416,7 @@ void Core_SetTest::run( int ) storage.release(); } } - catch(int) + catch(const int &) { } } @@ -1859,7 +1859,7 @@ void Core_GraphTest::run( int ) storage.release(); } } - catch(int) + catch(const int &) { } } @@ -2121,7 +2121,7 @@ void Core_GraphScanTest::run( int ) storage.release(); } } - catch(int) + catch(const int &) { } } diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index 22c24eaf63..89eac241c1 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -93,7 +93,7 @@ static bool ipp_Canny(const Mat& src , const Mat& dx_, const Mat& dy_, Mat& dst, CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterCannyDeriv, iwSrcDx, iwSrcDy, iwDst, low, high, ::ipp::IwiFilterCannyDerivParams(norm)); } - catch (::ipp::IwException ex) + catch (const ::ipp::IwException &) { return false; } @@ -119,7 +119,7 @@ static bool ipp_Canny(const Mat& src , const Mat& dx_, const Mat& dy_, Mat& dst, CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterCanny, iwSrc, iwDst, low, high, ::ipp::IwiFilterCannyParams(ippFilterSobel, kernel, norm), ippBorderRepl); } - catch (::ipp::IwException) + catch (const ::ipp::IwException &) { return false; } diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index a2e339c843..b83feceda9 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -337,7 +337,7 @@ static bool ipp_Deriv(InputArray _src, OutputArray _dst, int dx, int dy, int ksi if(useScale) CV_INSTRUMENT_FUN_IPP(::ipp::iwiScale, iwDstProc, iwDst, scale, delta, ::ipp::IwiScaleParams(ippAlgHintFast)); } - catch (::ipp::IwException) + catch (const ::ipp::IwException &) { return false; } @@ -765,7 +765,7 @@ static bool ipp_Laplacian(InputArray _src, OutputArray _dst, int ksize, double s CV_INSTRUMENT_FUN_IPP(::ipp::iwiScale, iwDstProc, iwDst, scale, delta); } - catch (::ipp::IwException ex) + catch (const ::ipp::IwException &) { return false; } diff --git a/modules/imgproc/src/morph.cpp b/modules/imgproc/src/morph.cpp index 66fae07fae..08a9969394 100644 --- a/modules/imgproc/src/morph.cpp +++ b/modules/imgproc/src/morph.cpp @@ -1299,7 +1299,7 @@ static bool ippMorph(int op, int src_type, int dst_type, CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterMorphology, iwSrc, iwDst, morphType, iwMask, ::ipp::IwDefault(), iwBorderType); } } - catch(::ipp::IwException ex) + catch(const ::ipp::IwException &) { return false; } diff --git a/modules/imgproc/src/resize.cpp b/modules/imgproc/src/resize.cpp index 688f4c7ff0..7eeefc7098 100644 --- a/modules/imgproc/src/resize.cpp +++ b/modules/imgproc/src/resize.cpp @@ -3241,7 +3241,7 @@ public: ::ipp::IwiTile tile = ::ipp::IwiRoi(0, range.start, m_dst.m_size.width, range.end - range.start); CV_INSTRUMENT_FUN_IPP(iwiResize, m_src, m_dst, ippBorderRepl, tile); } - catch(::ipp::IwException) + catch(const ::ipp::IwException &) { m_ok = false; return; @@ -3291,7 +3291,7 @@ public: ::ipp::IwiTile tile = ::ipp::IwiRoi(0, range.start, m_dst.m_size.width, range.end - range.start); CV_INSTRUMENT_FUN_IPP(iwiWarpAffine, m_src, m_dst, tile); } - catch(::ipp::IwException) + catch(const ::ipp::IwException &) { m_ok = false; return; @@ -3387,7 +3387,7 @@ static bool ipp_resize(const uchar * src_data, size_t src_step, int src_width, i if(!ok) return false; } - catch(::ipp::IwException) + catch(const ::ipp::IwException &) { return false; } diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index f327d9f067..3eb79594fe 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1510,7 +1510,7 @@ static bool ipp_boxfilter(Mat &src, Mat &dst, Size ksize, Point anchor, bool nor CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterBox, iwSrc, iwDst, iwKSize, ::ipp::IwDefault(), ippBorder); } - catch (::ipp::IwException) + catch (const ::ipp::IwException &) { return false; } @@ -4000,7 +4000,7 @@ public: ::ipp::IwiTile tile = ::ipp::IwiRoi(0, range.start, m_dst.m_size.width, range.end - range.start); CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterGaussian, m_src, m_dst, m_kernelSize, m_sigma, ::ipp::IwDefault(), m_border, tile); } - catch(::ipp::IwException e) + catch(const ::ipp::IwException &) { *m_pOk = false; return; @@ -4067,7 +4067,7 @@ static bool ipp_GaussianBlur(InputArray _src, OutputArray _dst, Size ksize, CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterGaussian, iwSrc, iwDst, ksize.width, sigma1, ::ipp::IwDefault(), ippBorder); } } - catch (::ipp::IwException ex) + catch (const ::ipp::IwException &) { return false; } @@ -5878,7 +5878,7 @@ public: ::ipp::IwiTile tile = ::ipp::IwiRoi(0, range.start, dst.m_size.width, range.end - range.start); CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterBilateral, src, dst, radius, valSquareSigma, posSquareSigma, ::ipp::IwDefault(), borderType, tile); } - catch(::ipp::IwException) + catch(const ::ipp::IwException &) { *pOk = false; return; @@ -5933,7 +5933,7 @@ static bool ipp_bilateralFilter(Mat &src, Mat &dst, int d, double sigmaColor, do CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterBilateral, iwSrc, iwDst, radius, valSquareSigma, posSquareSigma, ::ipp::IwDefault(), ippBorder); } } - catch (::ipp::IwException) + catch (const ::ipp::IwException &) { return false; } -- GitLab