From 0d8149d4ff49e1172ed96d3c90c406aaf6db2609 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 21 Sep 2024 22:46:00 +1000 Subject: [PATCH] Cleanup: various non-functional changes - Use const pointers. - Avoid shadowing variables. - Remove redundant check. --- source/blender/animrig/intern/action.cc | 4 ++-- source/blender/blenkernel/intern/ipo.cc | 6 +++--- source/blender/blenkernel/intern/lib_id.cc | 4 ++-- source/blender/editors/curve/editcurve.cc | 3 ++- .../editors/interface/interface_layout.cc | 2 +- .../blender/geometry/GEO_uv_parametrizer.hh | 6 +++--- .../geometry/intern/uv_parametrizer.cc | 20 +++++++++---------- .../windowmanager/intern/wm_gesture.cc | 2 +- .../windowmanager/intern/wm_toolsystem.cc | 8 ++++---- 9 files changed, 27 insertions(+), 28 deletions(-) diff --git a/source/blender/animrig/intern/action.cc b/source/blender/animrig/intern/action.cc index 6a0e5fa99a1..235bdd8755e 100644 --- a/source/blender/animrig/intern/action.cc +++ b/source/blender/animrig/intern/action.cc @@ -605,8 +605,8 @@ void Action::strip_keyframe_data_remove_if_unused(const int index) BLI_assert(index >= 0 && index < this->strip_keyframe_data_array_num); /* Make sure the data isn't being used anywhere. */ - for (Layer *layer : this->layers()) { - for (Strip *strip : layer->strips()) { + for (const Layer *layer : this->layers()) { + for (const Strip *strip : layer->strips()) { if (strip->type() == Strip::Type::Keyframe && strip->data_index == index) { return; } diff --git a/source/blender/blenkernel/intern/ipo.cc b/source/blender/blenkernel/intern/ipo.cc index 5312faaaa2e..7a7b7b0765c 100644 --- a/source/blender/blenkernel/intern/ipo.cc +++ b/source/blender/blenkernel/intern/ipo.cc @@ -1624,7 +1624,7 @@ static void icu_to_fcurves(ID *id, if ((id) && (icu->blocktype == GS(id->name)) && (GS(id->name) == ID_CU_LEGACY) && (fcu->rna_path && STREQ(fcu->rna_path, "eval_time"))) { - Curve *cu = (Curve *)id; + const Curve *cu = (const Curve *)id; dst->vec[0][1] *= cu->pathlen; dst->vec[1][1] *= cu->pathlen; @@ -1637,8 +1637,8 @@ static void icu_to_fcurves(ID *id, * - were also degrees/10 */ if (fcu->driver && fcu->driver->variables.first) { - DriverVar *dvar = static_cast(fcu->driver->variables.first); - DriverTarget *dtar = &dvar->targets[0]; + const DriverVar *dvar = static_cast(fcu->driver->variables.first); + const DriverTarget *dtar = &dvar->targets[0]; if (ELEM(dtar->transChan, DTAR_TRANSCHAN_ROTX, DTAR_TRANSCHAN_ROTY, DTAR_TRANSCHAN_ROTZ)) { diff --git a/source/blender/blenkernel/intern/lib_id.cc b/source/blender/blenkernel/intern/lib_id.cc index d9de808b3dd..032d94ceb71 100644 --- a/source/blender/blenkernel/intern/lib_id.cc +++ b/source/blender/blenkernel/intern/lib_id.cc @@ -1656,7 +1656,7 @@ ID *BKE_libblock_find_name(Main *bmain, const char *name, const std::optional lib) { - ListBase *lb = which_libbase(bmain, type); + const ListBase *lb = which_libbase(bmain, type); BLI_assert(lb != nullptr); ID *id = static_cast(BLI_findstring(lb, name, offsetof(ID, name) + 2)); @@ -1671,7 +1671,7 @@ ID *BKE_libblock_find_name(Main *bmain, ID *BKE_libblock_find_session_uid(Main *bmain, const short type, const uint32_t session_uid) { - ListBase *lb = which_libbase(bmain, type); + const ListBase *lb = which_libbase(bmain, type); BLI_assert(lb != nullptr); LISTBASE_FOREACH (ID *, id, lb) { if (id->session_uid == session_uid) { diff --git a/source/blender/editors/curve/editcurve.cc b/source/blender/editors/curve/editcurve.cc index 1ace0074324..e228c1061aa 100644 --- a/source/blender/editors/curve/editcurve.cc +++ b/source/blender/editors/curve/editcurve.cc @@ -658,7 +658,8 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) float(*ofs)[3] = nullptr; std::optional> dependent; - float *oldkey, *newkey, *ofp; + const float *oldkey, *ofp; + float *newkey; /* editing the base key should update others */ if (cu->key->type == KEY_RELATIVE) { diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index 5045a5b9152..d8115033eeb 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -2404,7 +2404,7 @@ void uiItemFullR(uiLayout *layout, if (is_id_name_prop) { Main *bmain = CTX_data_main(static_cast(block->evil_C)); ID *id = ptr->owner_id; - UI_but_func_rename_full_set(but, [bmain, id](std::string &new_name) { + UI_but_func_rename_full_set(but, [bmain, id](const std::string &new_name) { ED_id_rename(*bmain, *id, new_name); WM_main_add_notifier(NC_ID | NA_RENAME, nullptr); }); diff --git a/source/blender/geometry/GEO_uv_parametrizer.hh b/source/blender/geometry/GEO_uv_parametrizer.hh index 14ac0a9173d..bf7281d5409 100644 --- a/source/blender/geometry/GEO_uv_parametrizer.hh +++ b/source/blender/geometry/GEO_uv_parametrizer.hh @@ -91,13 +91,13 @@ void uv_parametrizer_face_add(ParamHandle *handle, const ParamKey *vkeys, const float **co, float **uv, /* Output will eventually be written to `uv`. */ - float *weight, + const float *weight, const bool *pin, const bool *select); -void uv_parametrizer_edge_set_seam(ParamHandle *handle, ParamKey *vkeys); +void uv_parametrizer_edge_set_seam(ParamHandle *phandle, const ParamKey *vkeys); -void uv_parametrizer_construct_end(ParamHandle *handle, +void uv_parametrizer_construct_end(ParamHandle *phandle, bool fill_holes, bool topology_from_uvs, int *r_count_failed = nullptr); diff --git a/source/blender/geometry/intern/uv_parametrizer.cc b/source/blender/geometry/intern/uv_parametrizer.cc index b13123a8788..5a9d17eae6d 100644 --- a/source/blender/geometry/intern/uv_parametrizer.cc +++ b/source/blender/geometry/intern/uv_parametrizer.cc @@ -2160,14 +2160,13 @@ static void p_chart_simplify_compute(PChart *chart, * is at the top of the respective lists. */ Heap *heap = BLI_heap_new(); - PVert *v; - PEdge *collapsededges = nullptr, *e; + PEdge *collapsededges = nullptr; int ncollapsed = 0; Vector wheelverts; wheelverts.reserve(16); /* insert all potential collapses into heap */ - for (v = chart->verts; v; v = v->nextlink) { + for (PVert *v = chart->verts; v; v = v->nextlink) { float cost; PEdge *e = nullptr; @@ -2181,7 +2180,7 @@ static void p_chart_simplify_compute(PChart *chart, } } - for (e = chart->edges; e; e = e->nextlink) { + for (PEdge *e = chart->edges; e; e = e->nextlink) { e->u.nextcollapse = nullptr; } @@ -3891,7 +3890,7 @@ static void p_add_ngon(ParamHandle *handle, const float *tri_co[3] = {co[v0], co[v1], co[v2]}; float *tri_uv[3] = {uv[v0], uv[v1], uv[v2]}; - float *tri_weight = nullptr; + const float *tri_weight = nullptr; float tri_weight_tmp[3]; if (weight) { @@ -3917,7 +3916,7 @@ void uv_parametrizer_face_add(ParamHandle *phandle, const ParamKey *vkeys, const float **co, float **uv, - float *weight, + const float *weight, const bool *pin, const bool *select) { @@ -3934,8 +3933,7 @@ void uv_parametrizer_face_add(ParamHandle *phandle, permute.append_unchecked(i); } - int i = nverts - 1; - while (i >= 0) { + for (int i = nverts - 1; i >= 0;) { /* Just check the "ears" of the n-gon. * For quads, this is sufficient. * For pentagons and higher, we might miss internal duplicate triangles, but note @@ -4003,7 +4001,7 @@ void uv_parametrizer_face_add(ParamHandle *phandle, } } -void uv_parametrizer_edge_set_seam(ParamHandle *phandle, ParamKey *vkeys) +void uv_parametrizer_edge_set_seam(ParamHandle *phandle, const ParamKey *vkeys) { BLI_assert(phandle->state == PHANDLE_STATE_ALLOCATED); @@ -4470,7 +4468,7 @@ static bool p_validate_corrected_coords_point(const PEdge *corr_e, continue; } - if (!(e->face->flag & PFACE_DONE) && (e != corr_e)) { + if (!(e->face->flag & PFACE_DONE)) { continue; } @@ -5159,7 +5157,7 @@ static void slim_flush_uvs(ParamHandle *phandle, (*count_changed)++; } - std::vector &UV = mt_chart->uv_matrices; + const std::vector &UV = mt_chart->uv_matrices; for (v = chart->verts; v; v = v->nextlink) { if (v->flag & PVERT_PIN) { continue; diff --git a/source/blender/windowmanager/intern/wm_gesture.cc b/source/blender/windowmanager/intern/wm_gesture.cc index 4cd13fb8502..fcd60084aa9 100644 --- a/source/blender/windowmanager/intern/wm_gesture.cc +++ b/source/blender/windowmanager/intern/wm_gesture.cc @@ -506,7 +506,7 @@ static void wm_gesture_draw_polyline(wmGesture *gt) draw_start_vertex_circle(*gt, shdr_pos); } -static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt) +static void wm_gesture_draw_cross(const wmWindow *win, const wmGesture *gt) { const rcti *rect = static_cast(gt->customdata); const blender::int2 win_size = WM_window_native_pixel_size(win); diff --git a/source/blender/windowmanager/intern/wm_toolsystem.cc b/source/blender/windowmanager/intern/wm_toolsystem.cc index 65c97805bb6..d6b2fae4222 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.cc +++ b/source/blender/windowmanager/intern/wm_toolsystem.cc @@ -371,8 +371,8 @@ static void toolsystem_brush_activate_from_toolref_for_object_paint(const bConte * Activate a brush compatible with \a tref, call when the active tool changes. */ static void toolsystem_brush_activate_from_toolref(const bContext *C, - WorkSpace *workspace, - bToolRef *tref) + const WorkSpace *workspace, + const bToolRef *tref) { BLI_assert(tref->runtime->flag & TOOLREF_FLAG_USE_BRUSHES); @@ -1015,13 +1015,13 @@ void WM_toolsystem_update_from_context( bool WM_toolsystem_active_tool_is_brush(const bContext *C) { - bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C); + const bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C); return tref_rt && (tref_rt->flag & TOOLREF_FLAG_USE_BRUSHES); } bool WM_toolsystem_active_tool_has_custom_cursor(const bContext *C) { - bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C); + const bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C); return tref_rt && (tref_rt->cursor != WM_CURSOR_DEFAULT); }