diff options
author | Jacques Lucke <jacques@blender.org> | 2021-03-22 13:57:24 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-03-22 14:01:07 +0300 |
commit | 01b6c4b32bf0aa3f2add0d4d51de9f777cf5c51c (patch) | |
tree | 38ea49ab0bfd0cf2ad1b8979819cac658b3db2d1 /source/blender/nodes/shader/nodes/node_shader_map_range.cc | |
parent | ccb372d17c2db88141dc4511550daac024121eb9 (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/shader/nodes/node_shader_map_range.cc')
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_map_range.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc index 3aa533599cf..3b4ea3d1bdf 100644 --- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc +++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc @@ -95,13 +95,20 @@ class MapRangeFunction : public blender::fn::MultiFunction { public: MapRangeFunction(bool clamp) : clamp_(clamp) { - blender::fn::MFSignatureBuilder signature = this->get_builder("Map Range"); + static blender::fn::MFSignature signature = create_signature(); + this->set_signature(&signature); + } + + static blender::fn::MFSignature create_signature() + { + blender::fn::MFSignatureBuilder signature{"Map Range"}; signature.single_input<float>("Value"); signature.single_input<float>("From Min"); signature.single_input<float>("From Max"); signature.single_input<float>("To Min"); signature.single_input<float>("To Max"); signature.single_output<float>("Result"); + return signature.build(); } void call(blender::IndexMask mask, |