diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index 7e3626da5ef..829bcfbf91b 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -549,13 +549,8 @@ IndexMask CurvesGeometry::indices_for_curve_type(const CurveType type, Array CurvesGeometry::point_to_curve_map() const { - const OffsetIndices points_by_curve = this->points_by_curve(); Array map(this->points_num()); - threading::parallel_for(this->curves_range(), 1024, [&](const IndexRange range) { - for (const int i_curve : range) { - map.as_mutable_span().slice(points_by_curve[i_curve]).fill(i_curve); - } - }); + offset_indices::build_reverse_map(this->points_by_curve(), map); return map; } diff --git a/source/blender/blenkernel/intern/mesh_mapping.cc b/source/blender/blenkernel/intern/mesh_mapping.cc index b57164fae1e..1710c0b98bb 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.cc +++ b/source/blender/blenkernel/intern/mesh_mapping.cc @@ -526,11 +526,7 @@ namespace blender::bke::mesh_topology { Array build_loop_to_poly_map(const OffsetIndices polys) { Array map(polys.total_size()); - threading::parallel_for(polys.index_range(), 1024, [&](IndexRange range) { - for (const int64_t poly_i : range) { - map.as_mutable_span().slice(polys[poly_i]).fill(int(poly_i)); - } - }); + offset_indices::build_reverse_map(polys, map); return map; } diff --git a/source/blender/blenlib/BLI_offset_indices.hh b/source/blender/blenlib/BLI_offset_indices.hh index b374be8c43b..3fa8ce9dd2a 100644 --- a/source/blender/blenlib/BLI_offset_indices.hh +++ b/source/blender/blenlib/BLI_offset_indices.hh @@ -97,6 +97,12 @@ template class OffsetIndices { */ void accumulate_counts_to_offsets(MutableSpan counts_to_offsets, int start_offset = 0); +/** + * Create a map from indexed elements to the source indices, in other words from the larger array + * to the smaller array. + */ +void build_reverse_map(OffsetIndices offsets, MutableSpan r_map); + } // namespace blender::offset_indices namespace blender { diff --git a/source/blender/blenlib/intern/offset_indices.cc b/source/blender/blenlib/intern/offset_indices.cc index 2ac11fe631e..8b38d630b05 100644 --- a/source/blender/blenlib/intern/offset_indices.cc +++ b/source/blender/blenlib/intern/offset_indices.cc @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #include "BLI_offset_indices.hh" +#include "BLI_task.hh" namespace blender::offset_indices { @@ -16,4 +17,13 @@ void accumulate_counts_to_offsets(MutableSpan counts_to_offsets, const int counts_to_offsets.last() = offset; } +void build_reverse_map(OffsetIndices offsets, MutableSpan r_map) +{ + threading::parallel_for(offsets.index_range(), 1024, [&](const IndexRange range) { + for (const int64_t i : range) { + r_map.slice(offsets[i]).fill(i); + } + }); +} + } // namespace blender::offset_indices