BLI: Add "scatter" array_utils function
This function, the opposite of `gather`, would have been useful a few times in the past. For now, just use it once in sculpt undo code.
This commit is contained in:
parent
0f5abc5a8b
commit
6935cd0798
|
@ -66,6 +66,23 @@ inline void copy(const Span<T> src,
|
|||
[&](const int64_t i) { dst[i] = src[i]; });
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the specified indices of the destination with the values in the source span.
|
||||
*/
|
||||
template<typename T, typename IndexT>
|
||||
inline void scatter(const Span<T> src,
|
||||
const Span<IndexT> indices,
|
||||
MutableSpan<T> 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.
|
||||
*/
|
||||
|
|
|
@ -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<int> 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: {
|
||||
|
|
Loading…
Reference in New Issue