[Bf-blender-cvs] [9b6c5268bc2] master: Cleanup: Decrease indentation by returning early

Hans Goudey noreply at git.blender.org
Fri Sep 25 22:55:28 CEST 2020


Commit: 9b6c5268bc2092614ec5b3fa1f6b98731cad4622
Author: Hans Goudey
Date:   Fri Sep 25 15:51:56 2020 -0500
Branches: master
https://developer.blender.org/rB9b6c5268bc2092614ec5b3fa1f6b98731cad4622

Cleanup: Decrease indentation by returning early

Where the if statement was just a check for an error or an unhandled
condition and there are no else statements, the rest of the function
doesn't need to be indented.

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

M	source/blender/editors/interface/interface.c

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 99f2066a656..bdc00b985bc 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -721,25 +721,22 @@ static bool ui_but_equals_old(const uiBut *but, const uiBut *oldbut)
 
 uiBut *ui_but_find_old(uiBlock *block_old, const uiBut *but_new)
 {
-  uiBut *but_old = NULL;
   LISTBASE_FOREACH (uiBut *, but, &block_old->buttons) {
     if (ui_but_equals_old(but_new, but)) {
-      but_old = but;
-      break;
+      return but;
     }
   }
-  return but_old;
+  return NULL;
 }
+
 uiBut *ui_but_find_new(uiBlock *block_new, const uiBut *but_old)
 {
-  uiBut *but_new = NULL;
   LISTBASE_FOREACH (uiBut *, but, &block_new->buttons) {
     if (ui_but_equals_old(but, but_old)) {
-      but_new = but;
-      break;
+      return but;
     }
   }
-  return but_new;
+  return NULL;
 }
 
 static bool ui_but_extra_icons_equals_old(const uiButExtraOpIcon *new_extra_icon,
@@ -1063,48 +1060,53 @@ static void ui_menu_block_set_keyaccels(uiBlock *block)
                 /* For PIE-menus. */
                 UI_BTYPE_ROW) ||
           (but->flag & UI_HIDDEN)) {
-        /* pass */
+        continue;
       }
-      else if (but->menu_key == '\0') {
-        if (but->str && but->str[0]) {
-          const char *str_pt = but->str;
-          uchar menu_key;
-          do {
-            menu_key = tolower(*str_pt);
-            if ((menu_key >= 'a' && menu_key <= 'z') && !(menu_key_mask & 1 << (menu_key - 'a'))) {
-              menu_key_mask |= 1 << (menu_key - 'a');
-              break;
-            }
 
-            if (pass == 0) {
-              /* Skip to next delimiter on first pass (be picky) */
-              while (isalpha(*str_pt)) {
-                str_pt++;
-              }
+      if (but->menu_key != '\0') {
+        continue;
+      }
 
-              if (*str_pt) {
-                str_pt++;
-              }
-            }
-            else {
-              /* just step over every char second pass and find first usable key */
-              str_pt++;
-            }
-          } while (*str_pt);
+      if (but->str == NULL || but->str[0] == '\0') {
+        continue;
+      }
 
-          if (*str_pt) {
-            but->menu_key = menu_key;
-          }
-          else {
-            /* run second pass */
-            tot_missing++;
+      const char *str_pt = but->str;
+      uchar menu_key;
+      do {
+        menu_key = tolower(*str_pt);
+        if ((menu_key >= 'a' && menu_key <= 'z') && !(menu_key_mask & 1 << (menu_key - 'a'))) {
+          menu_key_mask |= 1 << (menu_key - 'a');
+          break;
+        }
+
+        if (pass == 0) {
+          /* Skip to next delimiter on first pass (be picky) */
+          while (isalpha(*str_pt)) {
+            str_pt++;
           }
 
-          /* if all keys have been used just exit, unlikely */
-          if (menu_key_mask == (1 << 26) - 1) {
-            return;
+          if (*str_pt) {
+            str_pt++;
           }
         }
+        else {
+          /* just step over every char second pass and find first usable key */
+          str_pt++;
+        }
+      } while (*str_pt);
+
+      if (*str_pt) {
+        but->menu_key = menu_key;
+      }
+      else {
+        /* run second pass */
+        tot_missing++;
+      }
+
+      /* if all keys have been used just exit, unlikely */
+      if (menu_key_mask == (1 << 26) - 1) {
+        return;
       }
     }
 
@@ -1129,23 +1131,24 @@ void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_str
   }
 
   /* without this, just allow stripping of the shortcut */
-  if (shortcut_str) {
-    char *butstr_orig;
+  if (shortcut_str == NULL) {
+    return;
+  }
 
-    if (but->str != but->strdata) {
-      butstr_orig = but->str; /* free after using as source buffer */
-    }
-    else {
-      butstr_orig = BLI_strdup(but->str);
-    }
-    BLI_snprintf(
-        but->strdata, sizeof(but->strdata), "%s" UI_SEP_CHAR_S "%s", butstr_orig, shortcut_str);
-    MEM_freeN(butstr_orig);
-    but->str = but->strdata;
-    but->flag |= UI_BUT_HAS_SEP_CHAR;
-    but->drawflag |= UI_BUT_HAS_SHORTCUT;
-    ui_but_update(but);
+  char *butstr_orig;
+  if (but->str != but->strdata) {
+    butstr_orig = but->str; /* free after using as source buffer */
   }
+  else {
+    butstr_orig = BLI_strdup(but->str);
+  }
+  BLI_snprintf(
+      but->strdata, sizeof(but->strdata), "%s" UI_SEP_CHAR_S "%s", butstr_orig, shortcut_str);
+  MEM_freeN(butstr_orig);
+  but->str = but->strdata;
+  but->flag |= UI_BUT_HAS_SEP_CHAR;
+  but->drawflag |= UI_BUT_HAS_SHORTCUT;
+  ui_but_update(but);
 }
 
 /* -------------------------------------------------------------------- */
@@ -1325,72 +1328,75 @@ static bool ui_but_event_property_operator_string(const bContext *C,
   /* Don't use the button again. */
   but = NULL;
 
+  if (prop == NULL) {
+    return NULL;
+  }
+
   /* this version is only for finding hotkeys for properties
    * (which get set via context using operators) */
-  if (prop) {
-    /* to avoid massive slowdowns on property panels, for now, we only check the
-     * hotkeys for Editor / Scene settings...
-     *
-     * TODO: userpref settings?
-     */
-    char *data_path = NULL;
+  /* to avoid massive slowdowns on property panels, for now, we only check the
+   * hotkeys for Editor / Scene settings...
+   *
+   * TODO: userpref settings?
+   */
+  char *data_path = NULL;
 
-    if (ptr->owner_id) {
-      ID *id = ptr->owner_id;
+  if (ptr->owner_id) {
+    ID *id = ptr->owner_id;
 
-      if (GS(id->name) == ID_SCR) {
-        /* screen/editor property
-         * NOTE: in most cases, there is actually no info for backwards tracing
-         * how to get back to ID from the editor data we may be dealing with
-         */
-        if (RNA_struct_is_a(ptr->type, &RNA_Space)) {
-          /* data should be directly on here... */
-          data_path = BLI_sprintfN("space_data.%s", RNA_property_identifier(prop));
-        }
-        else if (RNA_struct_is_a(ptr->type, &RNA_Area)) {
-          /* data should be directly on here... */
-          const char *prop_id = RNA_property_identifier(prop);
-          /* Hack since keys access 'type', UI shows 'ui_type'. */
-          if (STREQ(prop_id, "ui_type")) {
-            prop_id = "type";
-            prop_enum_value >>= 16;
-            prop = RNA_struct_find_property(ptr, prop_id);
-
-            opnames = ctx_enum_opnames_for_Area_ui_type;
-            opnames_len = ARRAY_SIZE(ctx_enum_opnames_for_Area_ui_type);
-            prop_enum_value_id = "space_type";
-            prop_enum_value_is_int = true;
-          }
-          else {
-            data_path = BLI_sprintfN("area.%s", prop_id);
-          }
+    if (GS(id->name) == ID_SCR) {
+      /* screen/editor property
+       * NOTE: in most cases, there is actually no info for backwards tracing
+       * how to get back to ID from the editor data we may be dealing with
+       */
+      if (RNA_struct_is_a(ptr->type, &RNA_Space)) {
+        /* data should be directly on here... */
+        data_path = BLI_sprintfN("space_data.%s", RNA_property_identifier(prop));
+      }
+      else if (RNA_struct_is_a(ptr->type, &RNA_Area)) {
+        /* data should be directly on here... */
+        const char *prop_id = RNA_property_identifier(prop);
+        /* Hack since keys access 'type', UI shows 'ui_type'. */
+        if (STREQ(prop_id, "ui_type")) {
+          prop_id = "type";
+          prop_enum_value >>= 16;
+          prop = RNA_struct_find_property(ptr, prop_id);
+
+          opnames = ctx_enum_opnames_for_Area_ui_type;
+          opnames_len = ARRAY_SIZE(ctx_enum_opnames_for_Area_ui_type);
+          prop_enum_value_id = "space_type";
+          prop_enum_value_is_int = true;
         }
         else {
-          /* special exceptions for common nested data in editors... */
-          if (RNA_struct_is_a(ptr->type, &RNA_DopeSheet)) {
-            /* dopesheet filtering options... */
-            data_path = BLI_sprintfN("space_data.dopesheet.%s", RNA_property_identifier(prop));
-          }
-          else if (RNA_struct_is_a(ptr->type, &RNA_FileSelectParams)) {
-            /* Filebrowser options... */
-            data_path = BLI_sprintfN("space_data.params.%s", RNA_property_identifier(prop));
-          }
+          data_path = BLI_sprintfN("area.%s", prop_id);
         }
       }
-      else if (GS(id->name) == ID_SCE) {
-        if (RNA_struct_is_a(ptr->type, &RNA_ToolSettings)) {
-          /* Tool-settings property:
-           * NOTE: tool-settings is usually accessed directly (i.e. not through scene). */
-          data_path = RNA_path_from_ID_to_property(ptr, prop);
+      else {
+        /* special exceptions for common nested data in editors... */
+        if (RNA_struct_is_a(ptr->type, &RNA_DopeSheet)) {
+          /* dopesheet filtering options... */
+          data_path = BLI_sprintfN("space_data.dopesheet.%s", RNA_property_identifier(prop));
         }
-        else {
-          /* scene property */
-          char *path = RNA_path_from_ID_to_property(ptr, prop);
+        else if (RNA_struct_is_a(ptr->type, &RNA_FileSelectParams)) {
+          /* Filebrowser options... */
+          data_path = BLI_sprintfN("space_data.params.%s", RNA_property_identifier(prop));
+        }
+      }
+    }
+    else if (GS(id->name) == ID_SCE) {
+      if (RNA_struct_is_a(ptr->type, &RNA_ToolSettings)) {
+        /* Tool-settings property:
+         * NOTE: tool-settings is usually accessed directly (i.e. not through scene). */
+        data_path = RNA_path_from_ID_to_property(ptr, prop);
+      }
+      else {
+        /* scene property */
+        char *path = RNA_path_from_ID_to_property(ptr, prop);
 
-          if (path) {
-            data_path = BLI_sprintfN("scene.%s", path);
-            MEM_freeN(path);
-          }
+        if (path) {
+          data_path = BLI_sprintfN("scene.%s", path);
+          MEM_freeN(path);
+        }
 #if 0
           else {
             printf("ERROR in %s(): Couldn't get path for scene property - %s\n",
@@ -1398,69 +1404,68 @@ static bool ui_but_event

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list