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).
This commit is contained in:
2021-03-22 11:57:24 +01:00
parent ccb372d17c
commit 01b6c4b32b
16 changed files with 224 additions and 67 deletions

View File

@@ -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,

View File

@@ -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,