From 53b291c97059e65e3e277626a0115f94f20afb91 Mon Sep 17 00:00:00 2001 From: Fedor Chelnokov Date: Thu, 15 Oct 2026 11:59:31 +0300 Subject: [PATCH] reportProgress: take the callback by const reference Passing ProgressCallback by value copied the std::function on every call, which allocates when the callable does not fit the small buffer. Co-Authored-By: Claude Opus 5.5 --- source/MRMesh/MRProgressCallback.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/MRMesh/MRProgressCallback.h b/source/MRMesh/MRProgressCallback.h index 3b8e3efe3abd..5ad929c32dac 100644 --- a/source/MRMesh/MRProgressCallback.h +++ b/source/MRMesh/MRProgressCallback.h @@ -12,7 +12,7 @@ namespace MR { /// safely invokes \param cb with given value; just returning true for empty callback -inline bool reportProgress( ProgressCallback cb, float v ) +inline bool reportProgress( const ProgressCallback& cb, float v ) { if ( cb ) return cb( v ); @@ -21,7 +21,7 @@ inline bool reportProgress( ProgressCallback cb, float v ) /// safely invokes \param cb with given value if \param counter is divisible by \param divider (preferably a power of 2); /// just returning true for empty callback -inline bool reportProgress( ProgressCallback cb, float v, size_t counter, int divider ) +inline bool reportProgress( const ProgressCallback& cb, float v, size_t counter, int divider ) { if ( cb && ( counter % divider == 0 ) ) return cb( v ); @@ -31,7 +31,7 @@ inline bool reportProgress( ProgressCallback cb, float v, size_t counter, int di /// safely invokes \param cb with the value produced by given functor; /// just returning true for empty callback and not evaluating the function template -inline bool reportProgress( ProgressCallback cb, F && f ) +inline bool reportProgress( const ProgressCallback& cb, F && f ) { if ( cb ) return cb( f() ); @@ -41,7 +41,7 @@ inline bool reportProgress( ProgressCallback cb, F && f ) /// safely invokes \param cb with the value produced by given functor if \param counter is divisible by \param divider (preferably a power of 2); /// just returning true for empty callback and not evaluating the function template -inline bool reportProgress( ProgressCallback cb, F && f, size_t counter, int divider ) +inline bool reportProgress( const ProgressCallback& cb, F && f, size_t counter, int divider ) { if ( cb && ( counter % divider == 0 ) ) return cb( f() );