[Bf-blender-cvs] [0ca666880d4] virtual-array-attributes: simplify virtual array spans
Jacques Lucke
noreply at git.blender.org
Wed Apr 14 12:51:14 CEST 2021
Commit: 0ca666880d47cc4d3c3c06ad4521ff8f0c031196
Author: Jacques Lucke
Date: Wed Apr 14 12:06:11 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rB0ca666880d47cc4d3c3c06ad4521ff8f0c031196
simplify virtual array spans
===================================================================
M source/blender/blenlib/BLI_span.hh
M source/blender/blenlib/BLI_virtual_array.hh
M source/blender/nodes/geometry/nodes/node_geo_point_separate.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_span.hh b/source/blender/blenlib/BLI_span.hh
index fe511793c46..c32ba0826df 100644
--- a/source/blender/blenlib/BLI_span.hh
+++ b/source/blender/blenlib/BLI_span.hh
@@ -94,7 +94,7 @@ template<typename T> class Span {
using iterator = const T *;
using size_type = int64_t;
- private:
+ protected:
const T *data_ = nullptr;
int64_t size_ = 0;
@@ -477,7 +477,7 @@ template<typename T> class MutableSpan {
using iterator = T *;
using size_type = int64_t;
- private:
+ protected:
T *data_;
int64_t size_;
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index 2c31bd99700..e50e1a19f8e 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -384,13 +384,13 @@ template<typename T> class VArray_For_Single final : public VArray<T> {
* from faster access.
* - An API is called, that does not accept virtual arrays, but only spans.
*/
-template<typename T> class VArray_Span final : public VArray_For_Span<T> {
+template<typename T> class VArray_Span final : public Span<T> {
private:
const VArray<T> &varray_;
Array<T> owned_data_;
public:
- VArray_Span(const VArray<T> &varray) : VArray_For_Span<T>(varray.size()), varray_(varray)
+ VArray_Span(const VArray<T> &varray) : Span<T>(), varray_(varray)
{
if (varray_.is_span()) {
this->data_ = varray_.get_span().data();
@@ -401,25 +401,11 @@ template<typename T> class VArray_Span final : public VArray_For_Span<T> {
varray_.materialize_to_uninitialized(owned_data_);
this->data_ = owned_data_.data();
}
- }
-
- Span<T> as_span() const
- {
- return this->get_span();
- }
-
- operator Span<T>() const
- {
- return this->get_span();
- }
-
- IndexRange index_range() const
- {
- return IndexRange(this->size());
+ this->size_ = varray_.size();
}
};
-template<typename T> class VMutableArray_Span final : public VMutableArray_For_MutableSpan<T> {
+template<typename T> class VMutableArray_Span final : public MutableSpan<T> {
private:
VMutableArray<T> &varray_;
Array<T> owned_data_;
@@ -428,7 +414,7 @@ template<typename T> class VMutableArray_Span final : public VMutableArray_For_M
public:
VMutableArray_Span(VMutableArray<T> &varray, const bool materialize = true)
- : VMutableArray_For_MutableSpan<T>(varray.size()), varray_(varray)
+ : MutableSpan<T>(), varray_(varray)
{
if (varray_.is_span()) {
this->data_ = varray_.get_span().data();
@@ -444,6 +430,7 @@ template<typename T> class VMutableArray_Span final : public VMutableArray_For_M
}
this->data_ = owned_data_.data();
}
+ this->size_ = varray_.size();
}
~VMutableArray_Span()
@@ -461,43 +448,13 @@ template<typename T> class VMutableArray_Span final : public VMutableArray_For_M
if (this->data_ != owned_data_.data()) {
return;
}
- this->set_all(owned_data_);
+ varray_.set_all(owned_data_);
}
void disable_not_applied_warning()
{
show_not_applied_warning_ = false;
}
-
- Span<T> as_span() const
- {
- return this->get_span();
- }
-
- operator Span<T>() const
- {
- return this->get_span();
- }
-
- operator MutableSpan<T>()
- {
- return this->get_span();
- }
-
- T &operator[](const int64_t index)
- {
- return this->data_[index];
- }
-
- int64_t size() const
- {
- return this->size();
- }
-
- IndexRange index_range() const
- {
- return IndexRange(this->size());
- }
};
/**
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc b/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc
index d8a13d43953..930ecaa4c67 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc
@@ -76,7 +76,7 @@ static void copy_attributes_based_on_mask(const GeometryComponent &in_component,
GVArray_Typed<T> attribute_typed{*attribute.varray};
VArray_Span<T> span{attribute_typed};
MutableSpan<T> out_span = result_attribute.as_span<T>();
- copy_data_based_on_mask(span.as_span(), masks, invert, out_span);
+ copy_data_based_on_mask(span, masks, invert, out_span);
});
result_attribute.save();
@@ -111,16 +111,15 @@ static void separate_points_from_component(const GeometryComponent &in_component
const GVArray_Typed<bool> mask_attribute = in_component.attribute_get_for_read<bool>(
mask_name, ATTR_DOMAIN_POINT, false);
VArray_Span<bool> masks{mask_attribute};
- Span<bool> masks_span = masks.as_span();
- const int total = masks_span.count(!invert);
+ const int total = masks.count(!invert);
if (total == 0) {
return;
}
create_component_points(out_component, total);
- copy_attributes_based_on_mask(in_component, out_component, masks_span, invert);
+ copy_attributes_based_on_mask(in_component, out_component, masks, invert);
}
static GeometrySet separate_geometry_set(const GeometrySet &set_in,
More information about the Bf-blender-cvs
mailing list