Cleanup: various non-functional changes

- Use const arguments.
- Remove redundant cast.
- Use ELEM macro.
- Use boolean & nullptr literals.
This commit is contained in:
Campbell Barton
2024-08-26 11:34:42 +10:00
parent 74f240c3ce
commit 40f96afa61
23 changed files with 39 additions and 40 deletions

View File

@@ -172,7 +172,7 @@ static void array_shift_range(
BLI_assert(to <= num + range_start - range_end);
UNUSED_VARS_NDEBUG(num);
if (range_start == range_end || range_start == to) {
if (ELEM(range_start, range_end, to)) {
return;
}
@@ -1928,7 +1928,7 @@ ID *action_slot_get_id_best_guess(Main &bmain, Slot &slot, ID *primary_id)
{
blender::Span<ID *> users = slot.users(bmain);
if (users.is_empty()) {
return 0;
return nullptr;
}
if (users.contains(primary_id)) {
return primary_id;

View File

@@ -86,7 +86,7 @@ struct Main;
/**
* Mapping between names and ids.
*/
int BLO_get_struct_id_by_name(BlendWriter *writer, const char *struct_name);
int BLO_get_struct_id_by_name(const BlendWriter *writer, const char *struct_name);
#define BLO_get_struct_id(writer, struct_name) SDNA_TYPE_FROM_STRUCT(struct_name)
/**
@@ -146,7 +146,7 @@ void BLO_write_struct_array_at_address_by_id(
* Write struct list.
*/
void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name, ListBase *list);
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, ListBase *list);
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, const ListBase *list);
#define BLO_write_struct_list(writer, struct_name, list_ptr) \
BLO_write_struct_list_by_id(writer, BLO_get_struct_id(writer, struct_name), list_ptr)

View File

@@ -1874,7 +1874,7 @@ void BLO_write_struct_array_at_address_by_id(
writestruct_at_address_nr(writer->wd, BLO_CODE_DATA, struct_id, array_size, address, data_ptr);
}
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, ListBase *list)
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, const ListBase *list)
{
writelist_nr(writer->wd, BLO_CODE_DATA, struct_id, list);
}
@@ -1894,7 +1894,7 @@ void blo_write_id_struct(BlendWriter *writer, int struct_id, const void *id_addr
writestruct_at_address_nr(writer->wd, GS(id->name), struct_id, 1, id_address, id);
}
int BLO_get_struct_id_by_name(BlendWriter *writer, const char *struct_name)
int BLO_get_struct_id_by_name(const BlendWriter *writer, const char *struct_name)
{
int struct_id = DNA_struct_find_with_alias(writer->wd->sdna, struct_name);
return struct_id;

View File

@@ -95,12 +95,12 @@ TEST_F(ActionFilterTest, slots_expanded_or_not)
ASSERT_NE(nullptr, fcu_cube_loc_y);
/* Mock an bAnimContext for the Animation editor, with the above Animation showing. */
SpaceAction saction = {0};
SpaceAction saction = {nullptr};
saction.action = action;
saction.action_slot_handle = slot_cube.handle;
saction.ads.filterflag = ADS_FILTER_ALL_SLOTS;
bAnimContext ac = {0};
bAnimContext ac = {nullptr};
ac.bmain = bmain;
ac.datatype = ANIMCONT_ACTION;
ac.data = action;
@@ -249,12 +249,12 @@ TEST_F(ActionFilterTest, layered_action_active_fcurves)
fcurve_other->flag &= ~FCURVE_ACTIVE;
/* Mock an bAnimContext for the Action editor. */
SpaceAction saction = {0};
SpaceAction saction = {nullptr};
saction.action = action;
saction.action_slot_handle = slot_cube.handle;
saction.ads.filterflag = ADS_FILTER_ALL_SLOTS;
bAnimContext ac = {0};
bAnimContext ac = {nullptr};
ac.bmain = bmain;
ac.datatype = ANIMCONT_ACTION;
ac.data = action;

View File

@@ -551,7 +551,7 @@ void draw_grease_pencil_strokes(const RegionView3D &rv3d,
mat->gp_style->mode) :
GP_MATERIAL_MODE_LINE;
if (mat == 0 || (mat->gp_style->flag & GP_MATERIAL_HIDE)) {
if (mat == nullptr || (mat->gp_style->flag & GP_MATERIAL_HIDE)) {
return;
}

View File

@@ -68,9 +68,7 @@ DrawingPlacement::DrawingPlacement(const Scene &scene,
}
/* Account for layer transform. */
if (scene.toolsettings->gp_sculpt.lock_axis != GP_LOCKAXIS_VIEW &&
scene.toolsettings->gp_sculpt.lock_axis != GP_LOCKAXIS_CURSOR)
{
if (!ELEM(scene.toolsettings->gp_sculpt.lock_axis, GP_LOCKAXIS_VIEW, GP_LOCKAXIS_CURSOR)) {
/* Use the transpose inverse for normal. */
placement_normal_ = math::transform_direction(math::transpose(world_space_to_layer_space_),
placement_normal_);
@@ -154,7 +152,7 @@ DrawingPlacement::DrawingPlacement(const Scene &scene,
}
/* Account for layer transform. */
if (reproject_mode != ReprojectMode::View && reproject_mode != ReprojectMode::Cursor) {
if (!ELEM(reproject_mode, ReprojectMode::View, ReprojectMode::Cursor)) {
/* Use the transpose inverse for normal. */
placement_normal_ = math::transform_direction(math::transpose(world_space_to_layer_space_),
placement_normal_);

View File

@@ -323,7 +323,7 @@ static void eyedropper_gpencil_color_set(bContext *C,
/* Convert from linear rgb space to display space because palette and brush colors are in display
* space, and this conversion is needed to undo the conversion to linear performed by
* eyedropper_color_sample_fl. */
if ((eye->display) && (eye->mode == EyeMode::Palette || eye->mode == EyeMode::Brush)) {
if (eye->display && ELEM(eye->mode, EyeMode::Palette, EyeMode::Brush)) {
IMB_colormanagement_scene_linear_to_display_v3(col_conv, eye->display);
}

View File

@@ -1976,7 +1976,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region,
BLI_polyfill_calc(table_coords, tot_points, -1, tri_indices);
/* Draw the triangles for the profile fill. */
immUniformColor3ubvAlpha((const uchar *)wcol->item, 128);
immUniformColor3ubvAlpha(wcol->item, 128);
GPU_blend(GPU_BLEND_ALPHA);
GPU_polygon_smooth(false);
immBegin(GPU_PRIM_TRIS, 3 * tot_triangles);

View File

@@ -1378,7 +1378,7 @@ static void svg_replace_color_attributes(std::string &svg,
"{:02x}{:02x}{:02x}{:02x}", color[0], color[1], color[2], color[3]);
size_t att_start = start;
while (1) {
while (true) {
constexpr static blender::StringRef key = "fill=\"";
att_start = svg.find(key, att_start);
if (att_start == std::string::npos || att_start > end) {
@@ -1392,7 +1392,7 @@ static void svg_replace_color_attributes(std::string &svg,
}
att_start = start;
while (1) {
while (true) {
constexpr static blender::StringRef key = "fill:";
att_start = svg.find(key, att_start);
if (att_start == std::string::npos || att_start > end) {
@@ -1413,7 +1413,7 @@ static void icon_source_edit_cb(std::string &svg)
/* Scan string, processing only groups with our keyword ids. */
while (1) {
while (true) {
/* Look for a blender id, quick exit if not found. */
constexpr static blender::StringRef key = "id=\"";
const size_t id_start = svg.find(key + "blender_", g_start);

View File

@@ -884,7 +884,7 @@ static rctf get_boundary_bounds(const ARegion &region,
/* Check if the color is visible. */
const int material_index = materials[curve_i];
Material *mat = BKE_object_material_get(const_cast<Object *>(&object), material_index + 1);
if (mat == 0 || (mat->gp_style->flag & GP_MATERIAL_HIDE)) {
if (mat == nullptr || (mat->gp_style->flag & GP_MATERIAL_HIDE)) {
return;
}

View File

@@ -1321,7 +1321,7 @@ void restore_position_from_undo_step(const Depsgraph &depsgraph, Object &object)
/* Because brush deformation is calculated for the evaluated deformed positions,
* the translations have to be transformed to the original space. */
apply_crazyspace_to_translations(ss.deform_imats, verts, tls.translations);
if (active_key == nullptr || mesh.key->refkey == active_key) {
if (ELEM(active_key, nullptr, mesh.key->refkey)) {
/* We only ever want to propagate changes back to the base mesh if we either have
* no shape key active, or we are working on the basis shape key.
* See #126199 for more information. */

View File

@@ -425,7 +425,7 @@ void GPU_batch_draw_parameter_get(blender::gpu::Batch *batch,
/**
* Return vertex range for this #blender::gpu::Batch when using primitive expansions.
*/
blender::IndexRange GPU_batch_draw_expanded_parameter_get(blender::gpu::Batch *batch,
blender::IndexRange GPU_batch_draw_expanded_parameter_get(const blender::gpu::Batch *batch,
GPUPrimType expanded_prim_type,
int vertex_count,
int vertex_first);

View File

@@ -343,7 +343,7 @@ void GPU_batch_draw_parameter_get(Batch *gpu_batch,
*r_instance_count = i_count;
}
blender::IndexRange GPU_batch_draw_expanded_parameter_get(blender::gpu::Batch *batch,
blender::IndexRange GPU_batch_draw_expanded_parameter_get(const blender::gpu::Batch *batch,
GPUPrimType expanded_prim_type,
int vertex_count,
int vertex_first)

View File

@@ -232,7 +232,7 @@ void GLStorageBuf::read(void *data)
/* Repeat until the data is ready. */
}
glDeleteSync(read_fence_);
read_fence_ = 0;
read_fence_ = nullptr;
memcpy(data, persistent_ptr_, size_in_bytes_);
}

View File

@@ -1567,7 +1567,7 @@ static int imb_exr_split_channel_name(ExrChannel *echan,
return 1;
}
static ExrLayer *imb_exr_get_layer(ListBase *lb, char *layname)
static ExrLayer *imb_exr_get_layer(ListBase *lb, const char *layname)
{
ExrLayer *lay = (ExrLayer *)BLI_findstring(lb, layname, offsetof(ExrLayer, name));
@@ -1580,7 +1580,7 @@ static ExrLayer *imb_exr_get_layer(ListBase *lb, char *layname)
return lay;
}
static ExrPass *imb_exr_get_pass(ListBase *lb, char *passname)
static ExrPass *imb_exr_get_pass(ListBase *lb, const char *passname)
{
ExrPass *pass = (ExrPass *)BLI_findstring(lb, passname, offsetof(ExrPass, name));

View File

@@ -776,8 +776,7 @@ static void scale_bilinear_func(
});
}
bool IMB_scale(
ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded)
bool IMB_scale(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

@@ -15,11 +15,11 @@ using namespace blender;
static constexpr int SRC_X = 5123;
static constexpr int SRC_Y = 4091;
static constexpr int DST_SMALLER_X = (int)(SRC_X * 0.21f);
static constexpr int DST_SMALLER_Y = (int)(SRC_Y * 0.67f);
static constexpr int DST_SMALLER_X = int(SRC_X * 0.21f);
static constexpr int DST_SMALLER_Y = int(SRC_Y * 0.67f);
static constexpr int DST_LARGER_X = (int)(SRC_X * 1.19f);
static constexpr int DST_LARGER_Y = (int)(SRC_Y * 2.13f);
static constexpr int DST_LARGER_X = int(SRC_X * 1.19f);
static constexpr int DST_LARGER_Y = int(SRC_Y * 2.13f);
static ImBuf *create_src_image(bool use_float)
{

View File

@@ -52,7 +52,7 @@ static float get_average(const Span<float> values)
static ColorGeometry4f get_average(const Span<ColorGeometry4f> values)
{
if (values.is_empty()) {
return ColorGeometry4f(0);
return ColorGeometry4f(nullptr);
}
/* ColorGeometry4f does not support arithmetic directly. */
Span<float4> rgba_values = values.cast<float4>();

View File

@@ -286,7 +286,7 @@ bool SVGImporter::read(StringRefNull filepath)
constexpr float svg_dpi = 96.0f;
char abs_filepath[FILE_MAX];
BLI_strncpy(abs_filepath, filepath.c_str(), sizeof(abs_filepath));
STRNCPY(abs_filepath, filepath.c_str());
BLI_path_abs(abs_filepath, BKE_main_blendfile_path_from_global());
NSVGimage *svg_data = nullptr;

View File

@@ -550,7 +550,7 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
const int mat4x4f_struct_index = DNA_struct_find_index_without_alias_ex(
sdna, "mat4x4f", &dummy_index);
if (mat4x4f_struct_index > 0) {
SDNA_Struct *struct_info = sdna->structs[mat4x4f_struct_index];
const SDNA_Struct *struct_info = sdna->structs[mat4x4f_struct_index];
const int mat4x4f_type_index = struct_info->type_index;
sdna->types_alignment[mat4x4f_type_index] = alignof(blender::float4x4);
}

View File

@@ -478,7 +478,9 @@ static size_t seq_disk_cache_write_header(FILE *file, const DiskCacheHeader *hea
return fwrite(header, sizeof(*header), 1, file);
}
static int seq_disk_cache_add_header_entry(SeqCacheKey *key, ImBuf *ibuf, DiskCacheHeader *header)
static int seq_disk_cache_add_header_entry(const SeqCacheKey *key,
ImBuf *ibuf,
DiskCacheHeader *header)
{
int i;
uint64_t offset = sizeof(*header);
@@ -528,7 +530,7 @@ static int seq_disk_cache_add_header_entry(SeqCacheKey *key, ImBuf *ibuf, DiskCa
return i;
}
static int seq_disk_cache_get_header_entry(SeqCacheKey *key, const DiskCacheHeader *header)
static int seq_disk_cache_get_header_entry(const SeqCacheKey *key, const DiskCacheHeader *header)
{
for (int i = 0; i < DCACHE_IMAGES_PER_FILE; i++) {
if (header->entry[i].frameno == key->frame_index) {

View File

@@ -960,7 +960,7 @@ static void do_blend_effect_float(
}
static void do_blend_effect_byte(
float fac, int x, int y, uchar *rect1, uchar *rect2, int btype, uchar *out)
float fac, int x, int y, const uchar *rect1, uchar *rect2, int btype, uchar *out)
{
switch (btype) {
case SEQ_TYPE_ADD:

View File

@@ -415,7 +415,7 @@ void SEQ_retiming_remove_multiple_keys(Sequence *seq,
}
/* Sanitize keys to be removed. */
keys_to_remove.remove_if([&](SeqRetimingKey *key) {
keys_to_remove.remove_if([&](const SeqRetimingKey *key) {
return key->strip_frame_index == 0 || SEQ_retiming_is_last_key(seq, key) ||
SEQ_retiming_key_is_transition_type(key);
});