[Bf-blender-cvs] [a5081896bc0] master: Cleanup: redundant code, minor inconsistencies

Campbell Barton noreply at git.blender.org
Mon Jan 4 07:41:51 CET 2021


Commit: a5081896bc0416f9b64ae8e488bfe1cc2042ca7e
Author: Campbell Barton
Date:   Mon Jan 4 14:02:58 2021 +1100
Branches: master
https://developer.blender.org/rBa5081896bc0416f9b64ae8e488bfe1cc2042ca7e

Cleanup: redundant code, minor inconsistencies

- Remove ternary operators when both values are the same.
- Remove break after return.
- Remove redundant NULL checks for code which handles
  those cases immediately beforehand.

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

M	source/blender/blenkernel/intern/studiolight.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/space_nla/nla_channels.c
M	source/blender/editors/space_text/text_autocomplete.c
M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/modifiers/intern/MOD_smooth.c
M	source/blender/windowmanager/intern/wm_keymap.c

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

diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c
index 95186d2311a..b7b5b6997c2 100644
--- a/source/blender/blenkernel/intern/studiolight.c
+++ b/source/blender/blenkernel/intern/studiolight.c
@@ -306,19 +306,19 @@ static void UNUSED_FUNCTION(direction_to_cube_face_uv)(float r_uv[2],
     bool is_pos = (dir[0] > 0.0f);
     *r_face = is_pos ? STUDIOLIGHT_X_POS : STUDIOLIGHT_X_NEG;
     r_uv[0] = dir[2] / fabsf(dir[0]) * (is_pos ? 1 : -1);
-    r_uv[1] = dir[1] / fabsf(dir[0]) * (is_pos ? -1 : -1);
+    r_uv[1] = dir[1] / fabsf(dir[0]) * -1;
   }
   else if (fabsf(dir[1]) > fabsf(dir[0]) && fabsf(dir[1]) > fabsf(dir[2])) {
     bool is_pos = (dir[1] > 0.0f);
     *r_face = is_pos ? STUDIOLIGHT_Y_POS : STUDIOLIGHT_Y_NEG;
-    r_uv[0] = dir[0] / fabsf(dir[1]) * (is_pos ? 1 : 1);
+    r_uv[0] = dir[0] / fabsf(dir[1]) * 1;
     r_uv[1] = dir[2] / fabsf(dir[1]) * (is_pos ? -1 : 1);
   }
   else {
     bool is_pos = (dir[2] > 0.0f);
     *r_face = is_pos ? STUDIOLIGHT_Z_NEG : STUDIOLIGHT_Z_POS;
     r_uv[0] = dir[0] / fabsf(dir[2]) * (is_pos ? -1 : 1);
-    r_uv[1] = dir[1] / fabsf(dir[2]) * (is_pos ? -1 : -1);
+    r_uv[1] = dir[1] / fabsf(dir[2]) * -1;
   }
   r_uv[0] = r_uv[0] * 0.5f + 0.5f;
   r_uv[1] = r_uv[1] * 0.5f + 0.5f;
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 1059e37704a..622556943c9 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -722,9 +722,7 @@ static void gpencil_boundaryfill_area(tGPDfill *tgpf)
   }
 
   /* release ibuf */
-  if (ibuf) {
-    BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
-  }
+  BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
 
   tgpf->ima->id.tag |= LIB_TAG_DOIT;
   /* free temp stack data */
@@ -760,9 +758,7 @@ static void gpencil_set_borders(tGPDfill *tgpf, const bool transparent)
   }
 
   /* release ibuf */
-  if (ibuf) {
-    BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
-  }
+  BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
 
   tgpf->ima->id.tag |= LIB_TAG_DOIT;
 }
@@ -794,9 +790,7 @@ static void gpencil_invert_image(tGPDfill *tgpf)
   }
 
   /* release ibuf */
-  if (ibuf) {
-    BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
-  }
+  BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
 
   tgpf->ima->id.tag |= LIB_TAG_DOIT;
 }
@@ -846,9 +840,7 @@ static void gpencil_erase_processed_area(tGPDfill *tgpf)
   }
 
   /* release ibuf */
-  if (ibuf) {
-    BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
-  }
+  BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
 
   tgpf->ima->id.tag |= LIB_TAG_DOIT;
 }
@@ -1062,9 +1054,7 @@ static void gpencil_get_outline_points(tGPDfill *tgpf, const bool dilate)
   }
 
   /* release ibuf */
-  if (ibuf) {
-    BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
-  }
+  BKE_image_release_ibuf(tgpf->ima, ibuf, lock);
 }
 
 /* get z-depth array to reproject on surface */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index c3ac33063af..7c796f7b7a1 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -3207,7 +3207,7 @@ bGPDstroke *ED_gpencil_stroke_join_and_trim(
     bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps, bGPDstroke *gps_dst, const int pt_index)
 {
   if ((gps->totpoints < 1) || (gps_dst->totpoints < 1)) {
-    return false;
+    return NULL;
   }
   BLI_assert(pt_index >= 0 && pt_index < gps_dst->totpoints);
 
diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c
index 4e0f1462626..763a3fd63e6 100644
--- a/source/blender/editors/space_nla/nla_channels.c
+++ b/source/blender/editors/space_nla/nla_channels.c
@@ -586,7 +586,7 @@ static int nla_action_unlink_exec(bContext *C, wmOperator *op)
   }
 
   /* do unlinking */
-  if (adt && adt->action) {
+  if (adt->action) {
     bool force_delete = RNA_boolean_get(op->ptr, "force_delete");
     ED_animedit_unlink_action(C, adt_ptr.owner_id, adt, adt->action, op->reports, force_delete);
   }
diff --git a/source/blender/editors/space_text/text_autocomplete.c b/source/blender/editors/space_text/text_autocomplete.c
index 7d53f2a66cd..a38ed12e53b 100644
--- a/source/blender/editors/space_text/text_autocomplete.c
+++ b/source/blender/editors/space_text/text_autocomplete.c
@@ -57,7 +57,7 @@ bool text_do_suggest_select(SpaceText *st, ARegion *region, const int mval[2])
   int l, x, y, w, h, i;
   int tgti, *top;
 
-  if (!st || !st->text) {
+  if (!st->text) {
     return 0;
   }
   if (!texttool_text_is_active(st->text)) {
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 9b0ce27b1e3..f7ad7b9bdda 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -1075,9 +1075,7 @@ static void gizmo_ruler_exit(bContext *C, wmGizmo *gz, const bool cancel)
     view3d_ruler_to_gpencil(C, gzgroup);
   }
 
-  if (gz) {
-    MEM_SAFE_FREE(gz->interaction_data);
-  }
+  MEM_SAFE_FREE(gz->interaction_data);
 
   ruler_state_set(ruler_info, RULER_STATE_NORMAL);
 }
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index f082b0096a5..e8f1c26d17f 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1045,7 +1045,7 @@ static void rna_Object_active_material_set(PointerRNA *ptr,
   BLI_assert(BKE_id_is_in_global_main(value.data));
   BKE_object_material_assign(G_MAIN, ob, value.data, ob->actcol, BKE_MAT_ASSIGN_EXISTING);
 
-  if (ob && ob->type == OB_GPENCIL) {
+  if (ob->type == OB_GPENCIL) {
     /* notifying material property in topbar */
     WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, NULL);
   }
diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c
index 618ccc78279..c5011ed15c1 100644
--- a/source/blender/modifiers/intern/MOD_smooth.c
+++ b/source/blender/modifiers/intern/MOD_smooth.c
@@ -106,9 +106,7 @@ static void smoothModifier_do(
   uint *num_accumulated_vecs = MEM_calloc_arrayN(
       (size_t)numVerts, sizeof(*num_accumulated_vecs), __func__);
   if (!num_accumulated_vecs) {
-    if (accumulated_vecs) {
-      MEM_freeN(accumulated_vecs);
-    }
+    MEM_freeN(accumulated_vecs);
     return;
   }
 
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 1f730be8c82..8bfec0dc5c9 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -908,7 +908,6 @@ wmKeyMap *WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
     if (km->flag & KEYMAP_MODAL) {
       if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) {
         return km;
-        break;
       }
     }
   }



More information about the Bf-blender-cvs mailing list