Cleanup: various non-functional changes for C++

This commit is contained in:
Campbell Barton
2025-01-02 15:11:20 +11:00
parent 5c515e26bb
commit dca0996777
22 changed files with 42 additions and 38 deletions

View File

@@ -2035,7 +2035,7 @@ void BKE_grease_pencil_vgroup_name_update(Object *ob, const char *old_name, cons
Drawing &drawing = reinterpret_cast<GreasePencilDrawing *>(base)->wrap();
CurvesGeometry &curves = drawing.strokes_for_write();
LISTBASE_FOREACH (bDeformGroup *, vgroup, &curves.vertex_group_names) {
if (strcmp(vgroup->name, old_name) == 0) {
if (STREQ(vgroup->name, old_name)) {
STRNCPY(vgroup->name, new_name);
}
}

View File

@@ -916,7 +916,7 @@ static Drawing legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gp
stroke_cyclic.span[stroke_i] = (gps->flag & GP_STROKE_CYCLIC) != 0;
/* Truncating time in ms to uint32 then we don't lose precision in lower bits. */
const uint32_t clamped_init_time = static_cast<uint32_t>(
const uint32_t clamped_init_time = uint32_t(
std::clamp(gps->inittime * 1e3, 0.0, double(std::numeric_limits<uint32_t>::max())));
stroke_init_times.span[stroke_i] = float(clamped_init_time) / float(1e3);
stroke_start_caps.span[stroke_i] = int8_t(gps->caps[0]);

View File

@@ -1123,7 +1123,7 @@ Image *BKE_image_load_exists_in_lib(Main *bmain,
if (BLI_path_cmp(filepath_test, filepath_abs) != 0) {
continue;
}
if ((BKE_image_has_anim(ima)) && (ima->id.us != 0)) {
if (BKE_image_has_anim(ima) && (ima->id.us != 0)) {
/* TODO explain why animated images with already one or more users are skipped? */
continue;
}

View File

@@ -510,7 +510,7 @@ static float vfont_char_width(Curve *cu, VChar *che, const CharInfo *info)
static char32_t vfont_char_apply_smallcaps(char32_t charcode, const CharInfo *info)
{
if (UNLIKELY((info->flag & CU_CHINFO_SMALLCAPS_CHECK))) {
if (UNLIKELY(info->flag & CU_CHINFO_SMALLCAPS_CHECK)) {
return toupper(charcode);
}
return charcode;

View File

@@ -130,7 +130,7 @@ struct BVHRayCastData {
BVHTreeRay ray;
#ifdef USE_KDOPBVH_WATERTIGHT
struct IsectRayPrecalc isect_precalc;
IsectRayPrecalc isect_precalc;
#endif
/* initialized by bvhtree_ray_cast_data_precalc */
@@ -142,7 +142,7 @@ struct BVHRayCastData {
};
struct BVHNearestProjectedData {
struct DistProjectedAABBPrecalc precalc;
DistProjectedAABBPrecalc precalc;
bool closest_axis[3];
BVHTree_NearestProjectedCallback callback;
void *userdata;
@@ -759,7 +759,7 @@ static void non_recursive_bvh_div_nodes_task_cb(void *__restrict userdata,
break;
}
}
parent->node_num = (char)k;
parent->node_num = char(k);
}
/**
@@ -908,10 +908,10 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
/* Allocate arrays */
numnodes = maxsize + implicit_needed_branches(tree_type, maxsize) + tree_type;
tree->nodes = MEM_cnew_array<BVHNode *>((size_t)numnodes, "BVHNodes");
tree->nodebv = MEM_cnew_array<float>((size_t)(axis * numnodes), "BVHNodeBV");
tree->nodechild = MEM_cnew_array<BVHNode *>((size_t)(tree_type * numnodes), "BVHNodeBV");
tree->nodearray = MEM_cnew_array<BVHNode>((size_t)numnodes, "BVHNodeArray");
tree->nodes = MEM_cnew_array<BVHNode *>(size_t(numnodes), "BVHNodes");
tree->nodebv = MEM_cnew_array<float>(size_t(axis * numnodes), "BVHNodeBV");
tree->nodechild = MEM_cnew_array<BVHNode *>(size_t(tree_type * numnodes), "BVHNodeBV");
tree->nodearray = MEM_cnew_array<BVHNode>(size_t(numnodes), "BVHNodeArray");
if (UNLIKELY((!tree->nodes) || (!tree->nodebv) || (!tree->nodechild) || (!tree->nodearray))) {
goto fail;
@@ -1350,7 +1350,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
size_t total = 0;
BVHTreeOverlap *overlap = nullptr, *to = nullptr;
BVHOverlapData_Shared data_shared;
BVHOverlapData_Thread *data = BLI_array_alloca(data, (size_t)thread_num);
BVHOverlapData_Thread *data = BLI_array_alloca(data, size_t(thread_num));
axis_t start_axis, stop_axis;
/* check for compatibility of both trees (can't compare 14-DOP with 18-DOP) */
@@ -1418,12 +1418,12 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
MEM_mallocN(sizeof(BVHTreeOverlap) * total, "BVHTreeOverlap"));
for (j = 0; j < thread_num; j++) {
uint count = (uint)BLI_stack_count(data[j].overlap);
uint count = uint(BLI_stack_count(data[j].overlap));
BLI_stack_pop_n(data[j].overlap, to, count);
BLI_stack_free(data[j].overlap);
to += count;
}
*r_overlap_num = (uint)total;
*r_overlap_num = uint(total);
}
return overlap;
@@ -1520,11 +1520,11 @@ int *BLI_bvhtree_intersect_plane(const BVHTree *tree, float plane[4], uint *r_in
total = BLI_stack_count(data.intersect);
if (total) {
intersect = static_cast<int *>(MEM_mallocN(sizeof(int) * total, __func__));
BLI_stack_pop_n(data.intersect, intersect, (uint)total);
BLI_stack_pop_n(data.intersect, intersect, uint(total));
}
BLI_stack_free(data.intersect);
}
*r_intersect_num = (uint)total;
*r_intersect_num = uint(total);
return intersect;
}
@@ -2342,7 +2342,7 @@ int BLI_bvhtree_find_nearest_projected(const BVHTree *tree,
const BVHNode *root = tree->nodes[tree->leaf_num];
if (root != nullptr) {
BVHNearestProjectedData *data = (BVHNearestProjectedData *)alloca(
sizeof(*data) + (sizeof(*clip_plane) * (size_t)max_ii(1, clip_plane_len)));
sizeof(*data) + (sizeof(*clip_plane) * size_t(max_ii(1, clip_plane_len))));
dist_squared_to_projected_aabb_precalc(&data->precalc, projmat, winsize, mval);

View File

@@ -85,7 +85,7 @@ void BLI_covariance_m_vn_ex(const int n,
*/
const float covfac = 1.0f / float(use_sample_correction ? cos_vn_num - 1 : cos_vn_num);
memset(r_covmat, 0, sizeof(*r_covmat) * (size_t)(n * n));
memset(r_covmat, 0, sizeof(*r_covmat) * size_t(n * n));
CovarianceData data{};
data.cos_vn = cos_vn;

View File

@@ -143,7 +143,7 @@ struct PolyFill {
uint32_t tris_num;
#ifdef USE_KDTREE
struct KDTree2D kdtree;
KDTree2D kdtree;
#endif
};

View File

@@ -4054,7 +4054,7 @@ static BHead *find_bhead_from_idname(FileData *fd, const char *idname)
}
#ifdef USE_GHASH_BHEAD
char id_name_old[MAX_ID_NAME];
BLI_strncpy(id_name_old, idname, sizeof(id_name_old));
STRNCPY(id_name_old, idname);
*reinterpret_cast<short *>(id_name_old) = id_code_old;
return static_cast<BHead *>(BLI_ghash_lookup(fd->bhead_idname_hash, id_name_old));
#else

View File

@@ -5217,7 +5217,7 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
continue;
}
LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree->nodes) {
if (node->type == CMP_NODE_VIEWER || node->type == CMP_NODE_COMPOSITE) {
if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_COMPOSITE)) {
node->flag &= ~NODE_PREVIEW;
}
}

View File

@@ -585,7 +585,7 @@ static void rotate_to_plane(const JoinEdgesState &s,
#endif
for (int i = 0; i < 4; i++) {
if (quad_verts[i] == l_shared->v || quad_verts[i] == l_shared->next->v) {
if (ELEM(quad_verts[i], l_shared->v, l_shared->next->v)) {
/* Two coordinates of the quad match the vector that defines the axis of rotation, so they
* don't change. */
copy_v3_v3(r_quad_coordinates[i], quad_verts[i]->co);

View File

@@ -14,7 +14,7 @@
#include "RE_compositor.hh"
static constexpr float COM_PREVIEW_SIZE = 140.f;
static constexpr float COM_PREVIEW_SIZE = 140.0f;
static struct {
bool is_initialized = false;

View File

@@ -37,7 +37,7 @@ void VolumeProbeModule::init()
uint atlas_row_count = 0;
if (assign_if_different(irradiance_pool_size_,
(uint)inst_.scene->eevee.gi_irradiance_pool_size) ||
uint(inst_.scene->eevee.gi_irradiance_pool_size)) ||
!irradiance_atlas_tx_.is_valid())
{
irradiance_atlas_tx_.free();

View File

@@ -519,7 +519,7 @@ static std::tuple<int, int, float> preview_image_scaled_dimensions_get(const int
float scale;
float scaledx, scaledy;
if (((ui_imbx > layout.prv_w) || (ui_imby > layout.prv_h)) ||
(((ui_imbx < layout.prv_w) || (ui_imby < layout.prv_h))))
((ui_imbx < layout.prv_w) || (ui_imby < layout.prv_h)))
{
if (image_width > image_height) {
scaledx = float(layout.prv_w);

View File

@@ -506,7 +506,7 @@ void outliner_collection_isolate_flag(Scene *scene,
const bool value)
{
PointerRNA ptr;
const bool is_hide = strstr(propname, "hide_") || (strcmp(propname, "exclude") == 0);
const bool is_hide = strstr(propname, "hide_") || STREQ(propname, "exclude");
LayerCollection *top_layer_collection = layer_collection ?
static_cast<LayerCollection *>(

View File

@@ -307,7 +307,7 @@ void VKTexture::update_sub(
* other cases we unpack the rows to reduce the size of the staging buffer and data transfer. */
const uint texture_unpack_row_length =
context.state_manager_get().texture_unpack_row_length_get();
if (texture_unpack_row_length == 0 || texture_unpack_row_length == extent.x) {
if (ELEM(texture_unpack_row_length, 0, extent.x)) {
convert_host_to_device(
staging_buffer.mapped_memory_get(), data, sample_len, format, format_, device_format_);
}

View File

@@ -802,7 +802,7 @@ bool IMB_scale(ImBuf *ibuf, uint newx, uint newy, IMBScaleFilter filter, bool th
}
ImBuf *IMB_scale_into_new(
const ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded)
const ImBuf *ibuf, uint newx, uint newy, IMBScaleFilter filter, bool threaded)
{
BLI_assert_msg(newx > 0 && newy > 0, "Images must be at least 1 on both dimensions!");
if (ibuf == nullptr) {

View File

@@ -284,10 +284,14 @@ int ffmpeg_deinterlace(
{
int i, ret;
if (pix_fmt != AV_PIX_FMT_YUV420P && pix_fmt != AV_PIX_FMT_YUVJ420P &&
pix_fmt != AV_PIX_FMT_YUV422P && pix_fmt != AV_PIX_FMT_YUVJ422P &&
pix_fmt != AV_PIX_FMT_YUV444P && pix_fmt != AV_PIX_FMT_YUV411P &&
pix_fmt != AV_PIX_FMT_GRAY8)
if (!ELEM(pix_fmt,
AV_PIX_FMT_YUV420P,
AV_PIX_FMT_YUVJ420P,
AV_PIX_FMT_YUV422P,
AV_PIX_FMT_YUVJ422P,
AV_PIX_FMT_YUV444P,
AV_PIX_FMT_YUV411P,
AV_PIX_FMT_GRAY8))
{
return -1;
}

View File

@@ -26,7 +26,7 @@ bool test_vcodec(const AVCodec *codec, AVPixelFormat pixelformat)
ctx->pix_fmt = pixelformat;
ctx->width = 720;
ctx->height = 576;
int open = avcodec_open2(ctx, codec, NULL);
int open = avcodec_open2(ctx, codec, nullptr);
if (open >= 0) {
avcodec_free_context(&ctx);
result = true;
@@ -50,7 +50,7 @@ bool test_acodec(const AVCodec *codec, AVSampleFormat fmt)
av_channel_layout_from_mask(&ctx->ch_layout, AV_CH_LAYOUT_MONO);
#endif
ctx->bit_rate = 128000;
int open = avcodec_open2(ctx, codec, NULL);
int open = avcodec_open2(ctx, codec, nullptr);
if (open >= 0) {
avcodec_free_context(&ctx);
result = true;

View File

@@ -165,7 +165,7 @@ class ChannelMatteShaderNode : public ShaderNode {
GPUNodeStack *inputs = get_inputs_array();
GPUNodeStack *outputs = get_outputs_array();
const float color_space = static_cast<int>(get_color_space(bnode()));
const float color_space = int(get_color_space(bnode()));
const float matte_channel = get_matte_channel(bnode());
const float2 limit_channels = float2(get_limit_channels(bnode()));
const float max_limit = get_max_limit(bnode());

View File

@@ -78,7 +78,7 @@ static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &
static auto unpremultiply_function = mf::build::SI1_SO<float4, float4>(
"Alpha Convert Unpremultiply",
[](const float4 &color) -> float4 {
if (color.w == 0.0f || color.w == 1.0f) {
if (ELEM(color.w, 0.0f, 1.0f)) {
return color;
}
return float4(color.xyz() / color.w, color.w);

View File

@@ -109,7 +109,7 @@ static int seq_load_font_file(const std::string &path)
return fontid;
}
static int seq_load_font_mem(const std::string &name, const unsigned char *data, int data_size)
static int seq_load_font_mem(const std::string &name, const uchar *data, int data_size)
{
std::lock_guard lock(g_font_map.mutex);
int fontid = g_font_map.name_to_mem_font_id.add_or_modify(

View File

@@ -1059,7 +1059,7 @@ static void wm_gesture_straightline_do_angle_snap(rcti *rect, float snap_angle)
const float fract_90 = fractf(angle_snapped / DEG2RADF(90.0f));
/* Check if it's a multiple of 45 but not 90 degrees. */
if ((compare_ff(fract_45, 0.0f, 1e-6) || compare_ff(fabsf(fract_45), 1.0f, 1e-6)) &&
(!(compare_ff(fract_90, 0.0f, 1e-6) || compare_ff(fabsf(fract_90), 1.0f, 1e-6))))
!(compare_ff(fract_90, 0.0f, 1e-6) || compare_ff(fabsf(fract_90), 1.0f, 1e-6)))
{
int xlen = abs(rect->xmax - rect->xmin);
int ylen = rect->ymax - rect->ymin;