Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-03-22 13:57:24 +0300
committerJacques Lucke <jacques@blender.org>2021-03-22 14:01:07 +0300
commit01b6c4b32bf0aa3f2add0d4d51de9f777cf5c51c (patch)
tree38ea49ab0bfd0cf2ad1b8979819cac658b3db2d1 /source/blender/nodes/function
parentccb372d17c2db88141dc4511550daac024121eb9 (diff)
Functions: make multi functions smaller and cheaper to construct in many cases
Previously, the signature of a `MultiFunction` was always embedded into the function. There are two issues with that. First, `MFSignature` is relatively large, because it contains multiple strings and vectors. Secondly, constructing it can add overhead that should not be necessary, because often the same signature can be reused. The solution is to only keep a pointer to a signature in `MultiFunction` that is set during construction. Child classes are responsible for making sure that the signature lives long enough. In most cases, the signature is either embedded into the child class or it is allocated statically (and is only created once).
Diffstat (limited to 'source/blender/nodes/function')
-rw-r--r--source/blender/nodes/function/nodes/node_fn_object_transforms.cc9
-rw-r--r--source/blender/nodes/function/nodes/node_fn_random_float.cc9
2 files changed, 16 insertions, 2 deletions
diff --git a/source/blender/nodes/function/nodes/node_fn_object_transforms.cc b/source/blender/nodes/function/nodes/node_fn_object_transforms.cc
index 55f592d7879..a73049776e5 100644
--- a/source/blender/nodes/function/nodes/node_fn_object_transforms.cc
+++ b/source/blender/nodes/function/nodes/node_fn_object_transforms.cc
@@ -32,10 +32,17 @@ class ObjectTransformsFunction : public blender::fn::MultiFunction {
public:
ObjectTransformsFunction()
{
- blender::fn::MFSignatureBuilder signature = this->get_builder("Object Transforms");
+ static blender::fn::MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static blender::fn::MFSignature create_signature()
+ {
+ blender::fn::MFSignatureBuilder signature{"Object Transforms"};
signature.depends_on_context();
signature.single_input<blender::bke::PersistentObjectHandle>("Object");
signature.single_output<blender::float3>("Location");
+ return signature.build();
}
void call(blender::IndexMask mask,
diff --git a/source/blender/nodes/function/nodes/node_fn_random_float.cc b/source/blender/nodes/function/nodes/node_fn_random_float.cc
index 84ded73c601..d156cd431e0 100644
--- a/source/blender/nodes/function/nodes/node_fn_random_float.cc
+++ b/source/blender/nodes/function/nodes/node_fn_random_float.cc
@@ -37,11 +37,18 @@ class RandomFloatFunction : public blender::fn::MultiFunction {
public:
RandomFloatFunction(uint32_t function_seed) : function_seed_(function_seed)
{
- blender::fn::MFSignatureBuilder signature = this->get_builder("Random float");
+ static blender::fn::MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static blender::fn::MFSignature create_signature()
+ {
+ blender::fn::MFSignatureBuilder signature{"Random float"};
signature.single_input<float>("Min");
signature.single_input<float>("Max");
signature.single_input<int>("Seed");
signature.single_output<float>("Value");
+ return signature.build();
}
void call(blender::IndexMask mask,