[Bf-blender-cvs] [41ada0381c3] master: Cleanup: Animation, reduce indentation by reordering conditions

Sybren A. Stüvel noreply at git.blender.org
Fri Feb 7 16:42:22 CET 2020


Commit: 41ada0381c3b32eaa6c5508a65ed98f2bb391f61
Author: Sybren A. Stüvel
Date:   Fri Feb 7 14:02:11 2020 +0100
Branches: master
https://developer.blender.org/rB41ada0381c3b32eaa6c5508a65ed98f2bb391f61

Cleanup: Animation, reduce indentation by reordering conditions

This turns error condition checks into precondition checks, grouping the
non-error functionality together towards the bottom of the function and
error-handling functionality towards the top.

No functional changes.

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

M	source/blender/blenkernel/intern/fcurve.c

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

diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 5708cb0379b..254142fabab 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1320,60 +1320,7 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
   RNA_id_pointer_create(id, &id_ptr);
 
   /* get property to read from, and get value as appropriate */
-  if (RNA_path_resolve_property_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) {
-    if (RNA_property_array_check(prop)) {
-      /* array */
-      if ((index >= 0) && (index < RNA_property_array_length(&ptr, prop))) {
-        switch (RNA_property_type(prop)) {
-          case PROP_BOOLEAN:
-            value = (float)RNA_property_boolean_get_index(&ptr, prop, index);
-            break;
-          case PROP_INT:
-            value = (float)RNA_property_int_get_index(&ptr, prop, index);
-            break;
-          case PROP_FLOAT:
-            value = RNA_property_float_get_index(&ptr, prop, index);
-            break;
-          default:
-            break;
-        }
-      }
-      else {
-        /* out of bounds */
-        if (G.debug & G_DEBUG) {
-          CLOG_ERROR(&LOG,
-                     "Driver Evaluation Error: array index is out of bounds for %s -> %s (%d)",
-                     id->name,
-                     dtar->rna_path,
-                     index);
-        }
-
-        driver->flag |= DRIVER_FLAG_INVALID;
-        dtar->flag |= DTAR_FLAG_INVALID;
-        return 0.0f;
-      }
-    }
-    else {
-      /* not an array */
-      switch (RNA_property_type(prop)) {
-        case PROP_BOOLEAN:
-          value = (float)RNA_property_boolean_get(&ptr, prop);
-          break;
-        case PROP_INT:
-          value = (float)RNA_property_int_get(&ptr, prop);
-          break;
-        case PROP_FLOAT:
-          value = RNA_property_float_get(&ptr, prop);
-          break;
-        case PROP_ENUM:
-          value = (float)RNA_property_enum_get(&ptr, prop);
-          break;
-        default:
-          break;
-      }
-    }
-  }
-  else {
+  if (!RNA_path_resolve_property_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) {
     /* path couldn't be resolved */
     if (G.debug & G_DEBUG) {
       CLOG_ERROR(&LOG,
@@ -1387,6 +1334,57 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
     return 0.0f;
   }
 
+  if (RNA_property_array_check(prop)) {
+    /* array */
+    if (index < 0 || index >= RNA_property_array_length(&ptr, prop)) {
+      /* out of bounds */
+      if (G.debug & G_DEBUG) {
+        CLOG_ERROR(&LOG,
+                   "Driver Evaluation Error: array index is out of bounds for %s -> %s (%d)",
+                   id->name,
+                   dtar->rna_path,
+                   index);
+      }
+
+      driver->flag |= DRIVER_FLAG_INVALID;
+      dtar->flag |= DTAR_FLAG_INVALID;
+      return 0.0f;
+    }
+
+    switch (RNA_property_type(prop)) {
+      case PROP_BOOLEAN:
+        value = (float)RNA_property_boolean_get_index(&ptr, prop, index);
+        break;
+      case PROP_INT:
+        value = (float)RNA_property_int_get_index(&ptr, prop, index);
+        break;
+      case PROP_FLOAT:
+        value = RNA_property_float_get_index(&ptr, prop, index);
+        break;
+      default:
+        break;
+    }
+  }
+  else {
+    /* not an array */
+    switch (RNA_property_type(prop)) {
+      case PROP_BOOLEAN:
+        value = (float)RNA_property_boolean_get(&ptr, prop);
+        break;
+      case PROP_INT:
+        value = (float)RNA_property_int_get(&ptr, prop);
+        break;
+      case PROP_FLOAT:
+        value = RNA_property_float_get(&ptr, prop);
+        break;
+      case PROP_ENUM:
+        value = (float)RNA_property_enum_get(&ptr, prop);
+        break;
+      default:
+        break;
+    }
+  }
+
   /* if we're still here, we should be ok... */
   dtar->flag &= ~DTAR_FLAG_INVALID;
   return value;



More information about the Bf-blender-cvs mailing list