From 371237dcca83da2eda227b1b089f9e18a74fdf14 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 6 Nov 2024 12:49:12 +0100 Subject: [PATCH] Cleanup: Curves: Avoid random access to IndexMask This runs in logarithmic time and is bad for performance. It's better to use the iterators. --- source/blender/editors/curves/intern/curves_selection.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/curves/intern/curves_selection.cc b/source/blender/editors/curves/intern/curves_selection.cc index 53874c996d3..129bdd55a0b 100644 --- a/source/blender/editors/curves/intern/curves_selection.cc +++ b/source/blender/editors/curves/intern/curves_selection.cc @@ -771,7 +771,7 @@ static std::optional find_closest_point_to_screen_co( const float4x4 &projection, const IndexMask &points_mask, const float2 mouse_pos, - float radius, + const float radius, const FindClosestData &initial_closest) { const float radius_sq = pow2f(radius); @@ -781,8 +781,7 @@ static std::optional find_closest_point_to_screen_co( initial_closest, [&](const IndexRange range, const FindClosestData &init) { FindClosestData best_match = init; - for (const int index : range) { - const int point = points_mask[index]; + points_mask.slice(range).foreach_index([&](const int point) { const float3 &pos = positions[point]; const float2 pos_proj = ED_view3d_project_float_v2_m4(region, pos, projection); @@ -791,11 +790,11 @@ static std::optional find_closest_point_to_screen_co( distance_proj_sq > best_match.distance * best_match.distance) { /* Ignore the point because it's too far away or there is already a better point. */ - continue; + return; } best_match = {point, std::sqrt(distance_proj_sq)}; - } + }); return best_match; }, closer_elem);