From 056e3fc3943c6afc961abceaf825c554590ac852 Mon Sep 17 00:00:00 2001 From: Fedor Chelnokov Date: Thu, 15 Oct 2026 13:14:59 +0300 Subject: [PATCH] parallelFor, forAllRanged: take the progress callback by const reference Avoids copying the std::function on every call made with a named callback. Co-Authored-By: Claude Opus 5.5 --- source/MRMesh/MRBitSetParallelFor.cpp | 2 +- source/MRMesh/MRBitSetParallelFor.h | 2 +- source/MRMesh/MRParallelFor.cpp | 2 +- source/MRMesh/MRParallelFor.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/MRMesh/MRBitSetParallelFor.cpp b/source/MRMesh/MRBitSetParallelFor.cpp index eb30ed68a56b..eed6d44d74e0 100644 --- a/source/MRMesh/MRBitSetParallelFor.cpp +++ b/source/MRMesh/MRBitSetParallelFor.cpp @@ -66,7 +66,7 @@ void forAllRanged( const Range & bitRange, FunctionRef f, - FunctionRef ctx, ProgressCallback progressCb, size_t reportProgressEveryBit ) + FunctionRef ctx, const ProgressCallback& progressCb, size_t reportProgressEveryBit ) { if ( !progressCb ) { diff --git a/source/MRMesh/MRBitSetParallelFor.h b/source/MRMesh/MRBitSetParallelFor.h index 0c78e4a946a8..4c9f3efa3ea3 100644 --- a/source/MRMesh/MRBitSetParallelFor.h +++ b/source/MRMesh/MRBitSetParallelFor.h @@ -63,7 +63,7 @@ MRMESH_API void forAllRanged( const Range & bitRange, FunctionRef ctx ); MRMESH_API bool forAllRanged( const Range & bitRange, FunctionRef f, - FunctionRef ctx, ProgressCallback progressCb, size_t reportProgressEveryBit = 1024 ); + FunctionRef ctx, const ProgressCallback& progressCb, size_t reportProgressEveryBit = 1024 ); template auto ForAllRanged( const BS & bs, F && f, Cb && ... cb ) diff --git a/source/MRMesh/MRParallelFor.cpp b/source/MRMesh/MRParallelFor.cpp index cb534f59dca0..65af692ae215 100644 --- a/source/MRMesh/MRParallelFor.cpp +++ b/source/MRMesh/MRParallelFor.cpp @@ -36,7 +36,7 @@ void parallelFor( size_t begin, size_t end, FunctionRef } bool parallelFor( size_t begin, size_t end, FunctionRef f, FunctionRef ctx, - ProgressCallback cb, size_t reportProgressEvery ) + const ProgressCallback& cb, size_t reportProgressEvery ) { if ( !cb ) { diff --git a/source/MRMesh/MRParallelFor.h b/source/MRMesh/MRParallelFor.h index f5c9e1194959..f983d92b1427 100644 --- a/source/MRMesh/MRParallelFor.h +++ b/source/MRMesh/MRParallelFor.h @@ -21,7 +21,7 @@ MRMESH_API void parallelFor( size_t begin, size_t end, FunctionRef f, FunctionRef ctx ); MRMESH_API bool parallelFor( size_t begin, size_t end, FunctionRef f, FunctionRef ctx, - ProgressCallback cb, size_t reportProgressEvery = 1024 ); + const ProgressCallback& cb, size_t reportProgressEvery = 1024 ); /// executes given function f for each span element [begin, end); /// optional parameters after f: ProgressCallback cb, size_t reportProgressEvery = 1024 for periodic progress report