diff --git a/source/blender/blenlib/BLI_array_utils.hh b/source/blender/blenlib/BLI_array_utils.hh index fda1c32de35..500e35f5f33 100644 --- a/source/blender/blenlib/BLI_array_utils.hh +++ b/source/blender/blenlib/BLI_array_utils.hh @@ -66,6 +66,23 @@ inline void copy(const Span src, [&](const int64_t i) { dst[i] = src[i]; }); } +/** + * Fill the specified indices of the destination with the values in the source span. + */ +template +inline void scatter(const Span src, + const Span indices, + MutableSpan dst, + const int64_t grain_size = 4096) +{ + BLI_assert(indices.size() == src.size()); + threading::parallel_for(indices.index_range(), grain_size, [&](const IndexRange range) { + for (const int64_t i : range) { + dst[indices[i]] = src[i]; + } + }); +} + /** * Fill the destination span by gathering indexed values from the `src` array. */ diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index a64a61038ab..5ed88063fb7 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -1521,10 +1521,9 @@ static void paint_mesh_restore_node(Object *ob, case SCULPT_UNDO_MASK: { switch (BKE_pbvh_type(ss->pbvh)) { case PBVH_FACES: { - const Span verts = BKE_pbvh_node_get_unique_vert_indices(node); - for (const int i : verts.index_range()) { - mask_write.layer[verts[i]] = unode->mask[i]; - } + blender::array_utils::scatter(unode->mask.as_span(), + BKE_pbvh_node_get_unique_vert_indices(node), + {mask_write.layer, ss->totvert}); break; } case PBVH_BMESH: {