From b9a7b40924f6284af5867cb63078dc79c714a675 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 22 Apr 2021 08:05:02 -0500 Subject: Geometry Nodes: Get attribute domain and type without allocation Because we use virtual classes (and for other reasons), we had to do a small allocation when simply retrieving the data type and domain of an existing attribute. This happened quite a lot actually-- to determine these values for result attributes. This patch adds a simple function to retrieve this meta data without building the virtual array. This should lower the overhead of every attribute node, though the difference probably won't be noticible unless a tree has very many nodes. Differential Revision: https://developer.blender.org/D11047 --- source/blender/blenkernel/intern/attribute_access.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 3b2ee126d91..571763e3719 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -729,6 +729,20 @@ bool GeometryComponent::attribute_exists(const blender::StringRef attribute_name return false; } +std::optional GeometryComponent::attribute_get_meta_data( + const StringRef attribute_name) const +{ + std::optional result{std::nullopt}; + this->attribute_foreach([&](StringRefNull name, const AttributeMetaData &meta_data) { + if (attribute_name == name) { + result = meta_data; + return false; + } + return true; + }); + return result; +} + static std::unique_ptr try_adapt_data_type( std::unique_ptr varray, const blender::fn::CPPType &to_type) { -- cgit v1.2.3