diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh index 819807843df..c57c1dae961 100644 --- a/source/blender/blenlib/BLI_virtual_array.hh +++ b/source/blender/blenlib/BLI_virtual_array.hh @@ -156,15 +156,6 @@ template class VArrayImpl { { return false; } - - /** - * Return true when the other virtual array should be considered to be the same, e.g. because it - * shares the same underlying memory. - */ - virtual bool is_same(const VArrayImpl & /*other*/) const - { - return false; - } }; /** Similar to #VArrayImpl, but adds methods that allow modifying the referenced elements. */ @@ -238,18 +229,6 @@ template class VArrayImpl_For_Span : public VMutableArrayImpl { return CommonVArrayInfo(CommonVArrayInfo::Type::Span, true, data_); } - bool is_same(const VArrayImpl &other) const final - { - if (other.size() != this->size_) { - return false; - } - const CommonVArrayInfo other_info = other.common_info(); - if (other_info.type != CommonVArrayInfo::Type::Span) { - return false; - } - return data_ == static_cast(other_info.data); - } - void materialize(IndexMask mask, T *dst) const override { mask.foreach_index([&](const int64_t i) { dst[i] = data_[i]; }); @@ -482,23 +461,6 @@ class VArrayImpl_For_DerivedSpan final : public VMutableArrayImpl { } }); } - - bool is_same(const VArrayImpl &other) const override - { - if (other.size() != this->size_) { - return false; - } - if (const VArrayImpl_For_DerivedSpan *other_typed = - dynamic_cast *>(&other)) { - return other_typed->data_ == data_; - } - if (const VArrayImpl_For_DerivedSpan *other_typed = - dynamic_cast *>( - &other)) { - return other_typed->data_ == data_; - } - return false; - } }; template class VArrayCommon { return *static_cast(info.data); } - /** - * Return true when the other virtual references the same underlying memory. - */ - bool is_same(const VArrayCommon &other) const - { - if (!*this || !other) { - return false; - } - /* Check in both directions in case one does not know how to compare to the other - * implementation. */ - if (impl_->is_same(*other.impl_)) { - return true; - } - if (other.impl_->is_same(*impl_)) { - return true; - } - return false; - } - /** Copy the entire virtual array into a span. */ void materialize(MutableSpan r_span) const { diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc index caa911a5f45..2ad126567d1 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc @@ -29,9 +29,16 @@ static void set_computed_position_and_offset(GeometryComponent &component, const IndexMask selection) { MutableAttributeAccessor attributes = *component.attributes_for_write(); - const VArray positions_read_only = attributes.lookup("position"); - if (in_positions.is_same(positions_read_only)) { + /* Optimize the case when `in_positions` references the original positions array. */ + const VArray positions_read_only = attributes.lookup("position"); + bool positions_are_original = false; + if (positions_read_only.is_span() && in_positions.is_span()) { + positions_are_original = positions_read_only.get_internal_span().data() == + in_positions.get_internal_span().data(); + } + + if (positions_are_original) { if (const std::optional offset = in_offsets.get_if_single()) { if (math::is_zero(*offset)) { return; @@ -81,7 +88,7 @@ static void set_computed_position_and_offset(GeometryComponent &component, default: { AttributeWriter positions = attributes.lookup_for_write("position"); MutableVArraySpan out_positions_span = positions.varray; - if (in_positions.is_same(positions_read_only)) { + if (positions_are_original) { devirtualize_varray(in_offsets, [&](const auto in_offsets) { threading::parallel_for( selection.index_range(), grain_size, [&](const IndexRange range) {