[Bf-blender-cvs] [b1a607ce04f] master: Cleanup: deduplicate type conversion logic

Jacques Lucke noreply at git.blender.org
Tue Aug 3 10:40:36 CEST 2021


Commit: b1a607ce04fecae7af4474f7b087993ec2cf8e5b
Author: Jacques Lucke
Date:   Tue Aug 3 10:38:12 2021 +0200
Branches: master
https://developer.blender.org/rBb1a607ce04fecae7af4474f7b087993ec2cf8e5b

Cleanup: deduplicate type conversion logic

===================================================================

M	source/blender/modifiers/intern/MOD_nodes_evaluator.cc

===================================================================

diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 2157092d639..1391587fa7d 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -1245,14 +1245,8 @@ class GeometryNodesEvaluator {
     void *buffer = allocator.allocate(to_type.size(), to_type.alignment());
     GMutablePointer value{to_type, buffer};
 
-    if (conversions_.is_convertible(from_type, to_type)) {
-      /* Do the conversion if possible. */
-      conversions_.convert_to_uninitialized(from_type, to_type, value_to_forward.get(), buffer);
-    }
-    else {
-      /* Cannot convert, use default value instead. */
-      to_type.copy_construct(to_type.default_value(), buffer);
-    }
+    this->convert_value(from_type, to_type, value_to_forward.get(), buffer);
+
     /* Multi input socket values are logged once all values are available. */
     if (!to_socket->is_multi_input_socket()) {
       this->log_socket_value({to_socket}, value);
@@ -1380,17 +1374,29 @@ class GeometryNodesEvaluator {
     if (type == required_type) {
       return {type, buffer};
     }
-    if (conversions_.is_convertible(type, required_type)) {
-      /* Convert the loaded value to the required type if possible. */
-      void *converted_buffer = allocator.allocate(required_type.size(), required_type.alignment());
-      conversions_.convert_to_uninitialized(type, required_type, buffer, converted_buffer);
-      type.destruct(buffer);
-      return {required_type, converted_buffer};
+    void *converted_buffer = allocator.allocate(required_type.size(), required_type.alignment());
+    this->convert_value(type, required_type, buffer, converted_buffer);
+    return {required_type, converted_buffer};
+  }
+
+  void convert_value(const CPPType &from_type,
+                     const CPPType &to_type,
+                     const void *from_value,
+                     void *to_value)
+  {
+    if (from_type == to_type) {
+      from_type.copy_construct(from_value, to_value);
+      return;
+    }
+
+    if (conversions_.is_convertible(from_type, to_type)) {
+      /* Do the conversion if possible. */
+      conversions_.convert_to_uninitialized(from_type, to_type, from_value, to_value);
+    }
+    else {
+      /* Cannot convert, use default value instead. */
+      to_type.copy_construct(to_type.default_value(), to_value);
     }
-    /* Use a default fallback value when the loaded type is not compatible. */
-    void *default_buffer = allocator.allocate(required_type.size(), required_type.alignment());
-    required_type.copy_construct(required_type.default_value(), default_buffer);
-    return {required_type, default_buffer};
   }
 
   NodeState &get_node_state(const DNode node)



More information about the Bf-blender-cvs mailing list