[Bf-blender-cvs] [c6e3242e184] master: Cleanup: Use `switch` and `BLI_assert_unreachable()` more.

Bastien Montagne noreply at git.blender.org
Tue May 17 16:07:01 CEST 2022


Commit: c6e3242e1840b3df977288e126f5d625db2a4920
Author: Bastien Montagne
Date:   Tue May 17 15:11:13 2022 +0200
Branches: master
https://developer.blender.org/rBc6e3242e1840b3df977288e126f5d625db2a4920

Cleanup: Use `switch` and `BLI_assert_unreachable()` more.

Replace some `if/else if` chains by proper `switch` statement.

Replace some `BLI_assert(0)` calls by `BLI_assert_unreachable()` ones.

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

M	source/blender/blenlib/BLI_color_mix.hh
M	source/blender/blenlib/intern/BLI_ghash.c
M	source/blender/blenlib/intern/BLI_kdopbvh.c
M	source/blender/blenlib/intern/array_utils.c
M	source/blender/blenlib/intern/math_color.c
M	source/blender/blenlib/intern/math_matrix.c
M	source/blender/blenlib/intern/math_rotation.c
M	source/blender/blenlib/intern/string_cursor_utf8.c
M	source/blender/blenlib/intern/threads.cc
M	source/blender/blenlib/tests/BLI_array_store_test.cc

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

diff --git a/source/blender/blenlib/BLI_color_mix.hh b/source/blender/blenlib/BLI_color_mix.hh
index 4989ddc609e..322da2bf112 100644
--- a/source/blender/blenlib/BLI_color_mix.hh
+++ b/source/blender/blenlib/BLI_color_mix.hh
@@ -1042,7 +1042,7 @@ BLI_INLINE Color BLI_mix_colors(const IMB_BlendMode tool,
     case IMB_BLEND_COLOR:
       return mix_color<Color, Traits>(a, b, alpha);
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       return Color(0, 0, 0, 0);
   }
 }
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 57e05233efa..e6ff5bab8a1 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -173,7 +173,7 @@ BLI_INLINE uint ghash_find_next_bucket_index(const GHash *gh, uint curr_bucket)
       return curr_bucket;
     }
   }
-  BLI_assert(0);
+  BLI_assert_unreachable();
   return 0;
 }
 
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 0f52c84c45e..62bf17bd415 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -893,7 +893,7 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
     }
     else {
       /* should never happen! */
-      BLI_assert(0);
+      BLI_assert_unreachable();
 
       goto fail;
     }
diff --git a/source/blender/blenlib/intern/array_utils.c b/source/blender/blenlib/intern/array_utils.c
index f1f1dd60ddf..a401059755d 100644
--- a/source/blender/blenlib/intern/array_utils.c
+++ b/source/blender/blenlib/intern/array_utils.c
@@ -53,7 +53,7 @@ void _bli_array_wrap(void *arr_v, uint arr_len, size_t arr_stride, int dir)
     memcpy(arr, buf, arr_stride);
   }
   else {
-    BLI_assert(0);
+    BLI_assert_unreachable();
   }
 }
 
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 07e9eaf0f42..52cbda82268 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -166,7 +166,7 @@ void ycc_to_rgb(float y, float cb, float cr, float *r_r, float *r_g, float *r_b,
       b = y + 1.772f * cb - 226.816f;
       break;
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       break;
   }
   *r_r = r / 255.0f;
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index f295734706f..ce9abc36cad 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -1496,7 +1496,7 @@ void orthogonalize_m3(float R[3][3], int axis)
       }
       break;
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       break;
   }
   mul_v3_fl(R[0], size[0]);
@@ -1580,7 +1580,7 @@ void orthogonalize_m4(float R[4][4], int axis)
       }
       break;
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       break;
   }
   mul_v3_fl(R[0], size[0]);
@@ -1654,7 +1654,7 @@ void orthogonalize_m3_stable(float R[3][3], int axis, bool normalize)
       orthogonalize_stable(R[2], R[0], R[1], normalize);
       break;
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       break;
   }
 }
@@ -1672,7 +1672,7 @@ void orthogonalize_m4_stable(float R[4][4], int axis, bool normalize)
       orthogonalize_stable(R[2], R[0], R[1], normalize);
       break;
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       break;
   }
 }
@@ -1734,7 +1734,7 @@ static bool orthogonalize_m3_zero_axes_impl(float *mat[3], const float unit_leng
       break;
     }
     default: {
-      BLI_assert(0); /* Unreachable! */
+      BLI_assert_unreachable();
     }
   }
 
@@ -2338,7 +2338,7 @@ void rotate_m4(float mat[4][4], const char axis, const float angle)
       }
       break;
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       break;
   }
 }
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 4cd377b109e..92223bdf1d5 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -1143,7 +1143,7 @@ void axis_angle_to_mat3_single(float R[3][3], const char axis, const float angle
       R[2][2] = 1.0f;
       break;
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       break;
   }
 }
diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c
index a6e68401368..7a23b4bb4ad 100644
--- a/source/blender/blenlib/intern/string_cursor_utf8.c
+++ b/source/blender/blenlib/intern/string_cursor_utf8.c
@@ -198,7 +198,7 @@ void BLI_str_cursor_step_utf8(const char *str,
     }
   }
   else {
-    BLI_assert(0);
+    BLI_assert_unreachable();
   }
 }
 
@@ -296,6 +296,6 @@ void BLI_str_cursor_step_utf32(const char32_t *str,
     }
   }
   else {
-    BLI_assert(0);
+    BLI_assert_unreachable();
   }
 }
diff --git a/source/blender/blenlib/intern/threads.cc b/source/blender/blenlib/intern/threads.cc
index 70c1e701348..37fccf6f4fe 100644
--- a/source/blender/blenlib/intern/threads.cc
+++ b/source/blender/blenlib/intern/threads.cc
@@ -348,7 +348,7 @@ static ThreadMutex *global_mutex_from_type(const int type)
     case LOCK_VIEW3D:
       return &_view3d_lock;
     default:
-      BLI_assert(0);
+      BLI_assert_unreachable();
       return nullptr;
   }
 }
diff --git a/source/blender/blenlib/tests/BLI_array_store_test.cc b/source/blender/blenlib/tests/BLI_array_store_test.cc
index aa7291e1b41..20e2a4d88f8 100644
--- a/source/blender/blenlib/tests/BLI_array_store_test.cc
+++ b/source/blender/blenlib/tests/BLI_array_store_test.cc
@@ -644,7 +644,7 @@ static void testbuffer_list_state_random_data(ListBase *lb,
           break;
         }
         default:
-          BLI_assert(0);
+          BLI_assert_unreachable();
       }
     }
   }



More information about the Bf-blender-cvs mailing list