Cleanup: replace sizeof division with ARRAY_SIZE macro
This commit is contained in:
@@ -1757,14 +1757,13 @@ static void update_distances(int index,
|
||||
{0.0f, -1.0f, 1.0f}, {0.0f, -1.0f, -1.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f},
|
||||
{-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f},
|
||||
{-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}};
|
||||
size_t ray_cnt = sizeof ray_dirs / sizeof ray_dirs[0];
|
||||
|
||||
/* Count ray mesh misses (i.e. no face hit) and cases where the ray direction matches the face
|
||||
* normal direction. From this information it can be derived whether a cell is inside or
|
||||
* outside the mesh. */
|
||||
int miss_cnt = 0, dir_cnt = 0;
|
||||
|
||||
for (int i = 0; i < ray_cnt; i++) {
|
||||
for (int i = 0; i < ARRAY_SIZE(ray_dirs); i++) {
|
||||
BVHTreeRayHit hit_tree = {0};
|
||||
hit_tree.index = -1;
|
||||
hit_tree.dist = PHI_MAX;
|
||||
@@ -1798,7 +1797,7 @@ static void update_distances(int index,
|
||||
|
||||
/* Point lies inside mesh. Use negative sign for distance value.
|
||||
* This "if statement" has 2 conditions that can be true for points outside mesh. */
|
||||
if (!(miss_cnt > 0 || dir_cnt == ray_cnt)) {
|
||||
if (!(miss_cnt > 0 || dir_cnt == ARRAY_SIZE(ray_dirs))) {
|
||||
min_dist = (-1.0f) * fabsf(min_dist);
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ static AdrBit2Path ob_layer_bits[] = {
|
||||
/* quick macro for returning the appropriate array for adrcode_bitmaps_to_paths() */
|
||||
#define RET_ABP(items) \
|
||||
{ \
|
||||
*tot = sizeof(items) / sizeof(AdrBit2Path); \
|
||||
*tot = ARRAY_SIZE(items); \
|
||||
return items; \
|
||||
} \
|
||||
(void)0
|
||||
|
||||
@@ -130,7 +130,7 @@ typedef struct bUnitCollection {
|
||||
/* Keep table lignment. */
|
||||
/* clang-format off */
|
||||
|
||||
#define UNIT_COLLECTION_LENGTH(def) (sizeof(def) / sizeof(bUnitDef) - 1)
|
||||
#define UNIT_COLLECTION_LENGTH(def) (ARRAY_SIZE(def) - 1)
|
||||
#define NULL_UNIT {NULL, NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}
|
||||
|
||||
/* Dummy */
|
||||
|
||||
@@ -2363,8 +2363,8 @@ bool mat3_from_axis_conversion(
|
||||
value = ((src_forward << (0 * 3)) | (src_up << (1 * 3)) | (dst_forward << (2 * 3)) |
|
||||
(dst_up << (3 * 3)));
|
||||
|
||||
for (uint i = 0; i < (sizeof(_axis_convert_matrix) / sizeof(*_axis_convert_matrix)); i++) {
|
||||
for (uint j = 0; j < (sizeof(*_axis_convert_lut) / sizeof(*_axis_convert_lut[0])); j++) {
|
||||
for (uint i = 0; i < (ARRAY_SIZE(_axis_convert_matrix)); i++) {
|
||||
for (uint j = 0; j < (ARRAY_SIZE(*_axis_convert_lut)); j++) {
|
||||
if (_axis_convert_lut[i][j] == value) {
|
||||
copy_m3_m3(r_mat, _axis_convert_matrix[i]);
|
||||
return true;
|
||||
|
||||
@@ -508,11 +508,11 @@ void workbench_shader_free(void)
|
||||
struct GPUShader **sh_array = &e_data.transp_prepass_sh_cache[0][0][0][0];
|
||||
DRW_SHADER_FREE_SAFE(sh_array[j]);
|
||||
}
|
||||
for (int j = 0; j < sizeof(e_data.opaque_composite_sh) / sizeof(void *); j++) {
|
||||
for (int j = 0; j < ARRAY_SIZE(e_data.opaque_composite_sh); j++) {
|
||||
struct GPUShader **sh_array = &e_data.opaque_composite_sh[0];
|
||||
DRW_SHADER_FREE_SAFE(sh_array[j]);
|
||||
}
|
||||
for (int j = 0; j < sizeof(e_data.shadow_depth_pass_sh) / sizeof(void *); j++) {
|
||||
for (int j = 0; j < ARRAY_SIZE(e_data.shadow_depth_pass_sh); j++) {
|
||||
struct GPUShader **sh_array = &e_data.shadow_depth_pass_sh[0];
|
||||
DRW_SHADER_FREE_SAFE(sh_array[j]);
|
||||
}
|
||||
@@ -524,7 +524,7 @@ void workbench_shader_free(void)
|
||||
struct GPUShader **sh_array = &e_data.cavity_sh[0][0];
|
||||
DRW_SHADER_FREE_SAFE(sh_array[j]);
|
||||
}
|
||||
for (int j = 0; j < sizeof(e_data.smaa_sh) / sizeof(void *); j++) {
|
||||
for (int j = 0; j < ARRAY_SIZE(e_data.smaa_sh); j++) {
|
||||
struct GPUShader **sh_array = &e_data.smaa_sh[0];
|
||||
DRW_SHADER_FREE_SAFE(sh_array[j]);
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ static void prepare(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph)
|
||||
{FREESTYLE_FE_EXTERNAL_CONTOUR, 0},
|
||||
{FREESTYLE_FE_EDGE_MARK, 0},
|
||||
};
|
||||
int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition);
|
||||
int num_edge_types = ARRAY_SIZE(conditions);
|
||||
if (G.debug & G_DEBUG_FREESTYLE) {
|
||||
cout << "Linesets:" << endl;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ int ChainSilhouetteIterator::traverse(const AdjacencyIterator &ait)
|
||||
Nature::VALLEY,
|
||||
Nature::RIDGE,
|
||||
};
|
||||
int numNatures = sizeof(natures) / sizeof(Nature::EdgeNature);
|
||||
int numNatures = ARRAY_SIZE(natures);
|
||||
for (int i = 0; i < numNatures; ++i) {
|
||||
if (getCurrentEdge()->getNature() & natures[i]) {
|
||||
int n = 0;
|
||||
|
||||
@@ -207,7 +207,7 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
|
||||
|
||||
dpx->srcFormat = format_DPX;
|
||||
dpx->numElements = swap_ushort(header.imageHeader.elements_per_image, dpx->isMSB);
|
||||
size_t max_elements = sizeof(header.imageHeader.element) / sizeof(header.imageHeader.element[0]);
|
||||
size_t max_elements = ARRAY_SIZE(header.imageHeader.element);
|
||||
if (dpx->numElements == 0 || dpx->numElements >= max_elements) {
|
||||
if (verbose) {
|
||||
printf("DPX: Wrong number of elements: %d\n", dpx->numElements);
|
||||
|
||||
@@ -224,8 +224,7 @@ const ImFileType IMB_FILE_TYPES[] = {
|
||||
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0},
|
||||
};
|
||||
|
||||
const ImFileType *IMB_FILE_TYPES_LAST =
|
||||
&IMB_FILE_TYPES[sizeof(IMB_FILE_TYPES) / sizeof(ImFileType) - 1];
|
||||
const ImFileType *IMB_FILE_TYPES_LAST = &IMB_FILE_TYPES[ARRAY_SIZE(IMB_FILE_TYPES) - 1];
|
||||
|
||||
void imb_filetypes_init(void)
|
||||
{
|
||||
|
||||
@@ -3590,7 +3590,7 @@ static void rna_generate_struct_prototypes(FILE *f)
|
||||
if (found == 0) {
|
||||
fprintf(f, "struct %s;\n", struct_name);
|
||||
|
||||
if (all_structures >= sizeof(structures) / sizeof(structures[0])) {
|
||||
if (all_structures >= ARRAY_SIZE(structures)) {
|
||||
printf("Array size to store all structures names is too small\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user