Cleanup: redundant initialization

These were limited to obvious cases. Some less obvious cases
were kept as refactoring might make them necessary in future.
This commit is contained in:
2021-06-13 14:47:22 +10:00
parent f731bce6cd
commit ab38223047
26 changed files with 38 additions and 53 deletions

View File

@@ -1521,12 +1521,12 @@ void BKE_mesh_transform(Mesh *me, const float mat[4][4], bool do_keys)
void BKE_mesh_translate(Mesh *me, const float offset[3], const bool do_keys) void BKE_mesh_translate(Mesh *me, const float offset[3], const bool do_keys)
{ {
MVert *mvert = CustomData_duplicate_referenced_layer(&me->vdata, CD_MVERT, me->totvert); CustomData_duplicate_referenced_layer(&me->vdata, CD_MVERT, me->totvert);
/* If the referenced layer has been re-allocated need to update pointers stored in the mesh. */ /* If the referenced layer has been re-allocated need to update pointers stored in the mesh. */
BKE_mesh_update_customdata_pointers(me, false); BKE_mesh_update_customdata_pointers(me, false);
int i = me->totvert; int i = me->totvert;
for (mvert = me->mvert; i--; mvert++) { for (MVert *mvert = me->mvert; i--; mvert++) {
add_v3_v3(mvert->co, offset); add_v3_v3(mvert->co, offset);
} }

View File

@@ -2567,7 +2567,7 @@ bool BKE_mesh_center_median_from_polys(const Mesh *me, float r_cent[3])
const MLoop *mloop = me->mloop; const MLoop *mloop = me->mloop;
const MVert *mvert = me->mvert; const MVert *mvert = me->mvert;
zero_v3(r_cent); zero_v3(r_cent);
for (mpoly = me->mpoly; i--; mpoly++) { for (; i--; mpoly++) {
int loopend = mpoly->loopstart + mpoly->totloop; int loopend = mpoly->loopstart + mpoly->totloop;
for (int j = mpoly->loopstart; j < loopend; j++) { for (int j = mpoly->loopstart; j < loopend; j++) {
add_v3_v3(r_cent, mvert[mloop[j].v].co); add_v3_v3(r_cent, mvert[mloop[j].v].co);

View File

@@ -1879,12 +1879,11 @@ static const MeshElemMap *ccgDM_getPolyMap(Object *ob, DerivedMesh *dm)
/* WARNING! *MUST* be called in an 'loops_cache_rwlock' protected thread context! */ /* WARNING! *MUST* be called in an 'loops_cache_rwlock' protected thread context! */
static void ccgDM_recalcLoopTri(DerivedMesh *dm) static void ccgDM_recalcLoopTri(DerivedMesh *dm)
{ {
MLoopTri *mlooptri = dm->looptris.array;
const int tottri = dm->numPolyData * 2; const int tottri = dm->numPolyData * 2;
int i, poly_index; int i, poly_index;
DM_ensure_looptri_data(dm); DM_ensure_looptri_data(dm);
mlooptri = dm->looptris.array_wip; MLoopTri *mlooptri = dm->looptris.array_wip;
BLI_assert(tottri == 0 || mlooptri != NULL); BLI_assert(tottri == 0 || mlooptri != NULL);
BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num);

View File

@@ -1406,9 +1406,9 @@ static int find_cell_for_point_near_edge(mpq3 p,
int dummy_index = p_sorted_dummy - sorted_tris.begin(); int dummy_index = p_sorted_dummy - sorted_tris.begin();
int prev_tri = (dummy_index == 0) ? sorted_tris[sorted_tris.size() - 1] : int prev_tri = (dummy_index == 0) ? sorted_tris[sorted_tris.size() - 1] :
sorted_tris[dummy_index - 1]; sorted_tris[dummy_index - 1];
int next_tri = (dummy_index == sorted_tris.size() - 1) ? sorted_tris[0] :
sorted_tris[dummy_index + 1];
if (dbg_level > 0) { if (dbg_level > 0) {
int next_tri = (dummy_index == sorted_tris.size() - 1) ? sorted_tris[0] :
sorted_tris[dummy_index + 1];
std::cout << "prev tri to dummy = " << prev_tri << "; next tri to dummy = " << next_tri std::cout << "prev tri to dummy = " << prev_tri << "; next tri to dummy = " << next_tri
<< "\n"; << "\n";
} }

View File

@@ -3172,7 +3172,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
bool is_blend = false; bool is_blend = false;
{ {
char tool = tool_init; char tool;
switch (tool_init) { switch (tool_init) {
case PAINT_BLEND_MIX: case PAINT_BLEND_MIX:
tool = VPAINT_TOOL_DRAW; tool = VPAINT_TOOL_DRAW;

View File

@@ -7361,7 +7361,6 @@ static float geometry_collide_offset(BevelParams *bp, EdgeHalf *eb)
static float vertex_collide_offset(BevelParams *bp, EdgeHalf *ea) static float vertex_collide_offset(BevelParams *bp, EdgeHalf *ea)
{ {
float no_collide_offset = bp->offset + 1e6; float no_collide_offset = bp->offset + 1e6;
float limit = no_collide_offset;
if (bp->offset == 0.0f) { if (bp->offset == 0.0f) {
return no_collide_offset; return no_collide_offset;
} }
@@ -7373,8 +7372,7 @@ static float vertex_collide_offset(BevelParams *bp, EdgeHalf *ea)
if (kab <= 0.0f) { if (kab <= 0.0f) {
return no_collide_offset; return no_collide_offset;
} }
limit = la / kab; return la / kab;
return limit;
} }
/** /**

View File

@@ -320,7 +320,6 @@ bool id_copy_inplace_no_main(const ID *id, ID *newid)
* is already allocated. */ * is already allocated. */
bool scene_copy_inplace_no_main(const Scene *scene, Scene *new_scene) bool scene_copy_inplace_no_main(const Scene *scene, Scene *new_scene)
{ {
const ID *id_for_copy = &scene->id;
if (G.debug & G_DEBUG_DEPSGRAPH_UUID) { if (G.debug & G_DEBUG_DEPSGRAPH_UUID) {
SEQ_relations_check_uuids_unique_and_report(scene); SEQ_relations_check_uuids_unique_and_report(scene);
@@ -328,9 +327,10 @@ bool scene_copy_inplace_no_main(const Scene *scene, Scene *new_scene)
#ifdef NESTED_ID_NASTY_WORKAROUND #ifdef NESTED_ID_NASTY_WORKAROUND
NestedIDHackTempStorage id_hack_storage; NestedIDHackTempStorage id_hack_storage;
id_for_copy = nested_id_hack_get_discarded_pointers(&id_hack_storage, &scene->id); const ID *id_for_copy = nested_id_hack_get_discarded_pointers(&id_hack_storage, &scene->id);
#else
const ID *id_for_copy = &scene->id;
#endif #endif
bool result = (BKE_id_copy_ex(nullptr, bool result = (BKE_id_copy_ex(nullptr,
id_for_copy, id_for_copy,
(ID **)&new_scene, (ID **)&new_scene,

View File

@@ -2063,9 +2063,8 @@ static void draw_armature_pose(ArmatureDrawContext *ctx)
set_pchan_colorset(ctx, ob, pchan); set_pchan_colorset(ctx, ob, pchan);
} }
int boneflag = bone->flag;
/* catch exception for bone with hidden parent */ /* catch exception for bone with hidden parent */
boneflag = bone->flag; int boneflag = bone->flag;
if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) {
boneflag &= ~BONE_CONNECTED; boneflag &= ~BONE_CONNECTED;
} }

View File

@@ -6646,7 +6646,7 @@ void CURVE_OT_dissolve_verts(wmOperatorType *ot)
static bool nurb_bezt_flag_any(const Nurb *nu, const char flag_test) static bool nurb_bezt_flag_any(const Nurb *nu, const char flag_test)
{ {
BezTriple *bezt = nu->bezt; const BezTriple *bezt;
int i; int i;
for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) { for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) {

View File

@@ -387,7 +387,6 @@ static void curve_draw_stroke_3d(const struct bContext *UNUSED(C),
GPU_matrix_translate_3f(selem->location_local[0] - location_prev[0], GPU_matrix_translate_3f(selem->location_local[0] - location_prev[0],
selem->location_local[1] - location_prev[1], selem->location_local[1] - location_prev[1],
selem->location_local[2] - location_prev[2]); selem->location_local[2] - location_prev[2]);
location_prev = selem->location_local;
const float radius = stroke_elem_radius(cdd, selem); const float radius = stroke_elem_radius(cdd, selem);

View File

@@ -281,7 +281,6 @@ void ED_gpencil_trace_data_to_strokes(Main *bmain,
mat_mask_idx = ob->totcol - 1; mat_mask_idx = ob->totcol - 1;
} }
potrace_path_t *path = st->plist;
int n, *tag; int n, *tag;
potrace_dpoint_t(*c)[3]; potrace_dpoint_t(*c)[3];
@@ -289,7 +288,7 @@ void ED_gpencil_trace_data_to_strokes(Main *bmain,
* good results using the Potrace data. */ * good results using the Potrace data. */
const float scalef = 0.008f * scale; const float scalef = 0.008f * scale;
/* Draw each curve. */ /* Draw each curve. */
path = st->plist; potrace_path_t *path = st->plist;
while (path != NULL) { while (path != NULL) {
n = path->curve.n; n = path->curve.n;
tag = path->curve.tag; tag = path->curve.tag;

View File

@@ -149,7 +149,7 @@ static void join_mesh_single(Depsgraph *depsgraph,
mul_m4_m4m4(cmat, imat, ob_src->obmat); mul_m4_m4m4(cmat, imat, ob_src->obmat);
/* transform vertex coordinates into new space */ /* transform vertex coordinates into new space */
for (a = 0, mvert = *mvert_pp; a < me->totvert; a++, mvert++) { for (a = 0; a < me->totvert; a++, mvert++) {
mul_m4_v3(cmat, mvert->co); mul_m4_v3(cmat, mvert->co);
} }

View File

@@ -1189,9 +1189,7 @@ static SculptUndoNode *sculpt_undo_geometry_push(Object *object, SculptUndoType
static SculptUndoNode *sculpt_undo_face_sets_push(Object *ob, SculptUndoType type) static SculptUndoNode *sculpt_undo_face_sets_push(Object *ob, SculptUndoType type)
{ {
UndoSculpt *usculpt = sculpt_undo_get_nodes(); UndoSculpt *usculpt = sculpt_undo_get_nodes();
SculptUndoNode *unode = usculpt->nodes.first; SculptUndoNode *unode = MEM_callocN(sizeof(*unode), __func__);
unode = MEM_callocN(sizeof(*unode), __func__);
BLI_strncpy(unode->idname, ob->id.name, sizeof(unode->idname)); BLI_strncpy(unode->idname, ob->id.name, sizeof(unode->idname));
unode->type = type; unode->type = type;

View File

@@ -1235,10 +1235,8 @@ static void do_movie_proxy(void *pjv,
float *progress) float *progress)
{ {
ProxyJob *pj = pjv; ProxyJob *pj = pjv;
Scene *scene = pj->scene;
MovieClip *clip = pj->clip; MovieClip *clip = pj->clip;
struct MovieDistortion *distortion = NULL; struct MovieDistortion *distortion = NULL;
int cfra, sfra = SFRA, efra = EFRA;
if (pj->index_context) { if (pj->index_context) {
IMB_anim_index_rebuild(pj->index_context, stop, do_update, progress); IMB_anim_index_rebuild(pj->index_context, stop, do_update, progress);
@@ -1252,8 +1250,8 @@ static void do_movie_proxy(void *pjv,
return; return;
} }
sfra = 1; const int sfra = 1;
efra = clip->len; const int efra = clip->len;
if (build_undistort_count) { if (build_undistort_count) {
int threads = BLI_system_thread_count(); int threads = BLI_system_thread_count();
@@ -1265,7 +1263,7 @@ static void do_movie_proxy(void *pjv,
BKE_tracking_distortion_set_threads(distortion, threads); BKE_tracking_distortion_set_threads(distortion, threads);
} }
for (cfra = sfra; cfra <= efra; cfra++) { for (int cfra = sfra; cfra <= efra; cfra++) {
BKE_movieclip_build_proxy_frame( BKE_movieclip_build_proxy_frame(
clip, pj->clip_flag, distortion, cfra, build_undistort_sizes, build_undistort_count, 1); clip, pj->clip_flag, distortion, cfra, build_undistort_sizes, build_undistort_count, 1);

View File

@@ -1805,7 +1805,6 @@ static int graphkeys_mselect_column(bAnimContext *ac,
KeyframeEditFunc select_cb, ok_cb; KeyframeEditFunc select_cb, ok_cb;
KeyframeEditData ked; KeyframeEditData ked;
tNearestVertInfo *nvi; tNearestVertInfo *nvi;
float selx = (float)ac->scene->r.cfra;
/* find the beztriple that we're selecting, and the handle that was clicked on */ /* find the beztriple that we're selecting, and the handle that was clicked on */
nvi = find_nearest_fcurve_vert(ac, mval); nvi = find_nearest_fcurve_vert(ac, mval);
@@ -1817,7 +1816,7 @@ static int graphkeys_mselect_column(bAnimContext *ac,
/* get frame number on which elements should be selected */ /* get frame number on which elements should be selected */
/* TODO: should we restrict to integer frames only? */ /* TODO: should we restrict to integer frames only? */
selx = nvi->frame; const float selx = nvi->frame;
if (select_mode != SELECT_REPLACE) { if (select_mode != SELECT_REPLACE) {
/* Doesn't need to deselect anything -> Pass. */ /* Doesn't need to deselect anything -> Pass. */

View File

@@ -1311,7 +1311,6 @@ static int image_open_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C); Scene *scene = CTX_data_scene(C);
Object *obedit = CTX_data_edit_object(C); Object *obedit = CTX_data_edit_object(C);
ImageUser *iuser = NULL; ImageUser *iuser = NULL;
ImageOpenData *iod = op->customdata;
Image *ima = NULL; Image *ima = NULL;
int frame_seq_len = 0; int frame_seq_len = 0;
int frame_ofs = 1; int frame_ofs = 1;
@@ -1345,7 +1344,7 @@ static int image_open_exec(bContext *C, wmOperator *op)
} }
/* hook into UI */ /* hook into UI */
iod = op->customdata; ImageOpenData *iod = op->customdata;
if (iod->pprop.prop) { if (iod->pprop.prop) {
/* when creating new ID blocks, use is already 1, but RNA /* when creating new ID blocks, use is already 1, but RNA

View File

@@ -134,14 +134,12 @@ static void report_textview_end(TextViewContext *UNUSED(tvc))
static int report_textview_step(TextViewContext *tvc) static int report_textview_step(TextViewContext *tvc)
{ {
/* simple case, but no newline support */ /* simple case, but no newline support */
const Report *report = tvc->iter;
if (tvc->iter_char_begin <= 0) { if (tvc->iter_char_begin <= 0) {
tvc->iter = (void *)((Link *)tvc->iter)->prev; tvc->iter = (void *)((Link *)tvc->iter)->prev;
if (tvc->iter && report_textview_skip__internal(tvc)) { if (tvc->iter && report_textview_skip__internal(tvc)) {
tvc->iter_tmp++; tvc->iter_tmp++;
report = tvc->iter; const Report *report = tvc->iter;
tvc->iter_char_end = report->len; /* reset start */ tvc->iter_char_end = report->len; /* reset start */
report_textview_init__internal(tvc); report_textview_init__internal(tvc);

View File

@@ -89,7 +89,7 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
/* apply shrink/fatten */ /* apply shrink/fatten */
FOREACH_TRANS_DATA_CONTAINER (t, tc) { FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData *td = tc->data; TransData *td;
for (td = tc->data, i = 0; i < tc->data_len; i++, td++) { for (td = tc->data, i = 0; i < tc->data_len; i++, td++) {
if (td->flag & TD_SKIP) { if (td->flag & TD_SKIP) {
continue; continue;

View File

@@ -1072,7 +1072,7 @@ static void TargetSnapClosest(TransInfo *t)
if (t->options & CTX_OBJECT) { if (t->options & CTX_OBJECT) {
int i; int i;
FOREACH_TRANS_DATA_CONTAINER (t, tc) { FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData *td = tc->data; TransData *td;
for (td = tc->data, i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) { for (td = tc->data, i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
const BoundBox *bb = NULL; const BoundBox *bb = NULL;

View File

@@ -198,7 +198,7 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb)
* so we assign it based on the first segment we found. */ * so we assign it based on the first segment we found. */
ec->object_ref = e->object_ref; ec->object_ref = e->object_ref;
LineartEdge *new_e = e; LineartEdge *new_e;
LineartVert *new_vt; LineartVert *new_vt;
float N[3] = {0}; float N[3] = {0};

View File

@@ -159,7 +159,7 @@ void Shader::print_log(Span<const char *> sources, char *log, const char *stage,
} }
/* Print line from the source file that is producing the error. */ /* Print line from the source file that is producing the error. */
if ((error_line != -1) && (error_line != last_error_line || error_char != last_error_char)) { if ((error_line != -1) && (error_line != last_error_line || error_char != last_error_char)) {
const char *src_line_end = src_line; const char *src_line_end;
found_line_id = false; found_line_id = false;
/* error_line is 1 based in this case. */ /* error_line is 1 based in this case. */
int src_line_index = 1; int src_line_index = 1;

View File

@@ -1564,9 +1564,8 @@ DNA_ReconstructInfo *DNA_reconstruct_info_create(const SDNA *oldsdna,
ReconstructStep *steps = create_reconstruct_steps_for_struct( ReconstructStep *steps = create_reconstruct_steps_for_struct(
oldsdna, newsdna, compare_flags, old_struct, new_struct); oldsdna, newsdna, compare_flags, old_struct, new_struct);
int steps_len = new_struct->members_len;
/* Comment the line below to skip the compression for debugging purposes. */ /* Comment the line below to skip the compression for debugging purposes. */
steps_len = compress_reconstruct_steps(steps, new_struct->members_len); const int steps_len = compress_reconstruct_steps(steps, new_struct->members_len);
reconstruct_info->steps[new_struct_nr] = steps; reconstruct_info->steps[new_struct_nr] = steps;
reconstruct_info->step_counts[new_struct_nr] = steps_len; reconstruct_info->step_counts[new_struct_nr] = steps_len;

View File

@@ -1912,10 +1912,9 @@ static void rna_Scene_transform_orientation_slots_begin(CollectionPropertyIterat
iter, orient_slot, sizeof(*orient_slot), ARRAY_SIZE(scene->orientation_slots), 0, NULL); iter, orient_slot, sizeof(*orient_slot), ARRAY_SIZE(scene->orientation_slots), 0, NULL);
} }
static int rna_Scene_transform_orientation_slots_length(PointerRNA *ptr) static int rna_Scene_transform_orientation_slots_length(PointerRNA *UNUSED(ptr))
{ {
Scene *scene = (Scene *)ptr->owner_id; return ARRAY_SIZE(((Scene *)NULL)->orientation_slots);
return ARRAY_SIZE(scene->orientation_slots);
} }
static bool rna_Scene_use_audio_get(PointerRNA *ptr) static bool rna_Scene_use_audio_get(PointerRNA *ptr)

View File

@@ -1072,10 +1072,9 @@ static void rna_UserDef_studiolight_solid_lights_begin(CollectionPropertyIterato
rna_iterator_array_begin(iter, sl->light, sizeof(*sl->light), ARRAY_SIZE(sl->light), 0, NULL); rna_iterator_array_begin(iter, sl->light, sizeof(*sl->light), ARRAY_SIZE(sl->light), 0, NULL);
} }
static int rna_UserDef_studiolight_solid_lights_length(PointerRNA *ptr) static int rna_UserDef_studiolight_solid_lights_length(PointerRNA *UNUSED(ptr))
{ {
StudioLight *sl = (StudioLight *)ptr->data; return ARRAY_SIZE(((StudioLight *)NULL)->light);
return ARRAY_SIZE(sl->light);
} }
/* StudioLight.light_ambient */ /* StudioLight.light_ambient */

View File

@@ -409,7 +409,7 @@ Sequence *SEQ_add_sound_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqL
Strip *strip = seq->strip; Strip *strip = seq->strip;
/* We only need 1 element to store the filename. */ /* We only need 1 element to store the filename. */
StripElem *se = strip->stripdata = se = MEM_callocN(sizeof(StripElem), "stripelem"); StripElem *se = strip->stripdata = MEM_callocN(sizeof(StripElem), "stripelem");
BLI_split_dirfile(load_data->path, strip->dir, se->name, sizeof(strip->dir), sizeof(se->name)); BLI_split_dirfile(load_data->path, strip->dir, se->name, sizeof(strip->dir), sizeof(se->name));
if (seq != NULL && seq->sound != NULL) { if (seq != NULL && seq->sound != NULL) {

View File

@@ -911,7 +911,10 @@ void wm_homefile_read(bContext *C,
const char *app_template_override, const char *app_template_override,
bool *r_is_factory_startup) bool *r_is_factory_startup)
{ {
Main *bmain = G_MAIN; /* Context does not always have valid main pointer here... */ #if 0 /* UNUSED, keep as this may be needed later & the comment below isn't self evident. */
/* Context does not always have valid main pointer here. */
Main *bmain = G_MAIN;
#endif
ListBase wmbase; ListBase wmbase;
bool success = false; bool success = false;
@@ -1170,7 +1173,7 @@ void wm_homefile_read(bContext *C,
BLI_strncpy(U.app_template, app_template_override, sizeof(U.app_template)); BLI_strncpy(U.app_template, app_template_override, sizeof(U.app_template));
} }
bmain = CTX_data_main(C); Main *bmain = CTX_data_main(C);
if (use_userdef) { if (use_userdef) {
/* check userdef before open window, keymaps etc */ /* check userdef before open window, keymaps etc */
@@ -2482,12 +2485,11 @@ static void wm_open_mainfile_ui(bContext *UNUSED(C), wmOperator *op)
{ {
struct FileRuntime *file_info = (struct FileRuntime *)&op->customdata; struct FileRuntime *file_info = (struct FileRuntime *)&op->customdata;
uiLayout *layout = op->layout; uiLayout *layout = op->layout;
uiLayout *col = op->layout;
const char *autoexec_text; const char *autoexec_text;
uiItemR(layout, op->ptr, "load_ui", 0, NULL, ICON_NONE); uiItemR(layout, op->ptr, "load_ui", 0, NULL, ICON_NONE);
col = uiLayoutColumn(layout, false); uiLayout *col = uiLayoutColumn(layout, false);
if (file_info->is_untrusted) { if (file_info->is_untrusted) {
autoexec_text = IFACE_("Trusted Source [Untrusted Path]"); autoexec_text = IFACE_("Trusted Source [Untrusted Path]");
uiLayoutSetActive(col, false); uiLayoutSetActive(col, false);