Cleanup: make typed output attribute movable

This comes at a small performance cost due to an additional
memory allocation, but that is not significant currently.
This commit is contained in:
Jacques Lucke 2021-10-03 14:49:15 +02:00
parent 5d5a753d96
commit 8fc97a871f
1 changed files with 5 additions and 2 deletions

View File

@ -244,18 +244,21 @@ class OutputAttribute {
template<typename T> class OutputAttribute_Typed {
private:
OutputAttribute attribute_;
std::optional<fn::GVMutableArray_Typed<T>> optional_varray_;
std::unique_ptr<fn::GVMutableArray_Typed<T>> optional_varray_;
VMutableArray<T> *varray_ = nullptr;
public:
OutputAttribute_Typed(OutputAttribute attribute) : attribute_(std::move(attribute))
{
if (attribute_) {
optional_varray_.emplace(attribute_.varray());
optional_varray_ = std::make_unique<fn::GVMutableArray_Typed<T>>(attribute_.varray());
varray_ = &**optional_varray_;
}
}
OutputAttribute_Typed(OutputAttribute_Typed &&other) = default;
~OutputAttribute_Typed() = default;
operator bool() const
{
return varray_ != nullptr;