Cleanup: use const pointers/references

This commit is contained in:
Campbell Barton
2024-09-15 23:14:09 +10:00
parent 1104e4233d
commit 9b39b4c91c
27 changed files with 72 additions and 69 deletions

View File

@@ -329,7 +329,7 @@ static GHOST_TSuccess gwl_window_cursor_custom_load(const GWL_WindowCursorCustom
}
static GHOST_TSuccess gwl_window_cursor_shape_refresh(GHOST_TStandardCursor shape,
GWL_WindowCursorCustomShape &ccs,
const GWL_WindowCursorCustomShape &ccs,
GHOST_SystemWayland *system)
{
#ifdef USE_EVENT_BACKGROUND_THREAD

View File

@@ -1765,7 +1765,7 @@ bActionGroup *ChannelBag::channel_group_find(const StringRef name)
int ChannelBag::channel_group_containing_index(const int fcurve_array_index)
{
int i = 0;
for (bActionGroup *group : this->channel_groups()) {
for (const bActionGroup *group : this->channel_groups()) {
if (fcurve_array_index >= group->fcurve_range_start &&
fcurve_array_index < (group->fcurve_range_start + group->fcurve_range_length))
{
@@ -1787,7 +1787,7 @@ bActionGroup &ChannelBag::channel_group_create(StringRefNull name)
int fcurve_index = 0;
const int length = this->channel_groups().size();
if (length > 0) {
bActionGroup *last = this->channel_group(length - 1);
const bActionGroup *last = this->channel_group(length - 1);
fcurve_index = last->fcurve_range_start + last->fcurve_range_length;
}
new_group->fcurve_range_start = fcurve_index;
@@ -1805,7 +1805,7 @@ bActionGroup &ChannelBag::channel_group_create(StringRefNull name)
* match that system's behavior, even when it's goofy.*/
std::string unique_name = BLI_uniquename_cb(
[&](const StringRef name) {
for (bActionGroup *group : this->channel_groups()) {
for (const bActionGroup *group : this->channel_groups()) {
if (STREQ(group->name, name.data())) {
return true;
}
@@ -1841,7 +1841,7 @@ bool ChannelBag::channel_group_remove(bActionGroup &group)
/* Move the group's fcurves to just past the end of where the grouped
* fcurves will be after this group is removed. */
bActionGroup *last_group = this->channel_groups().last();
const bActionGroup *last_group = this->channel_groups().last();
BLI_assert(last_group != nullptr);
const int to_index = last_group->fcurve_range_start + last_group->fcurve_range_length -
group.fcurve_range_length;

View File

@@ -296,7 +296,7 @@ static void write_channelbag(BlendWriter *writer, animrig::ChannelBag &channelba
Span<bActionGroup *> groups = channelbag.channel_groups();
BLO_write_pointer_array(writer, groups.size(), groups.data());
for (bActionGroup *group : groups) {
for (const bActionGroup *group : groups) {
BLO_write_struct(writer, bActionGroup, group);
}

View File

@@ -621,7 +621,7 @@ static void loose_data_instantiate_obdata_preprocess(
continue;
}
if (idcode == ID_GD_LEGACY) {
bGPdata *legacy_gpd = reinterpret_cast<bGPdata *>(id);
const bGPdata *legacy_gpd = reinterpret_cast<bGPdata *>(id);
if ((legacy_gpd->flag & GP_DATA_ANNOTATIONS) != 0) {
continue;
}

View File

@@ -2671,7 +2671,7 @@ namespace blender::bke::nla {
bool foreach_strip(ID *id, blender::FunctionRef<bool(NlaStrip *)> callback)
{
AnimData *adt = BKE_animdata_from_id(id);
const AnimData *adt = BKE_animdata_from_id(id);
if (!adt) {
/* Having no NLA trivially means that we've looped through all the strips. */
return true;

View File

@@ -850,7 +850,7 @@ static int find_fill_primitive(const MeshData &mesh_data, UVBorderCorner &corner
if (corner.first->get_uv_vertex(0) == corner.second->get_uv_vertex(1)) {
return -1;
}
UVVertex *shared_vert = corner.second->get_uv_vertex(0);
const UVVertex *shared_vert = corner.second->get_uv_vertex(0);
for (const int edge_i : mesh_data.vert_to_edge_map[shared_vert->vertex]) {
const int2 &edge = mesh_data.edges[edge_i];
if (corner.first->edge->has_same_vertices(edge)) {

View File

@@ -879,11 +879,11 @@ std::optional<std::string> BKE_screen_path_from_screen_to_space(const PointerRNA
return std::nullopt;
}
bScreen *screen = reinterpret_cast<bScreen *>(ptr->owner_id);
SpaceLink *link = static_cast<SpaceLink *>(ptr->data);
const bScreen *screen = reinterpret_cast<const bScreen *>(ptr->owner_id);
const SpaceLink *link = static_cast<const SpaceLink *>(ptr->data);
int area_index;
LISTBASE_FOREACH_INDEX (ScrArea *, area, &screen->areabase, area_index) {
LISTBASE_FOREACH_INDEX (const ScrArea *, area, &screen->areabase, area_index) {
const int space_index = BLI_findindex(&area->spacedata, link);
if (space_index != -1) {
return fmt::format("areas[{}].spaces[{}]", area_index, space_index);

View File

@@ -1495,7 +1495,7 @@ template<typename T> static void re_delaunay_triangulate(CDTArrangement<T> *cdt,
}
/* `se` is a diagonal just added, and it is base of area to re-triangulate (face on its left). */
int count = 1;
for (SymEdge<T> *ss = se->next; ss != se; ss = ss->next) {
for (const SymEdge<T> *ss = se->next; ss != se; ss = ss->next) {
count++;
}
if (count <= 3) {

View File

@@ -142,7 +142,9 @@ static char *generate(blender::Map<std::string, std::string> &messages, size_t *
for (const auto message_items_iter : messages.items()) {
items.append(Item(message_items_iter));
}
std::sort(items.begin(), items.end(), [](Item &a, Item &b) -> bool { return a.key < b.key; });
std::sort(items.begin(), items.end(), [](const Item &a, const Item &b) -> bool {
return a.key < b.key;
});
Offset *offsets = MEM_cnew_array<Offset>(num_keys, __func__);
uint32_t tot_keys_len = 0;

View File

@@ -1238,7 +1238,7 @@ static int gpencil_camera_view_subrect(bContext *C, rctf *subrect)
/* for camera view set the subrect */
if (rv3d->persp == RV3D_CAMOB) {
Scene *scene = CTX_data_scene(C);
const Scene *scene = CTX_data_scene(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, subrect, true);
return 1;

View File

@@ -72,12 +72,12 @@ static bool gpencil_stroke_paintmode_poll_with_tool(bContext *C, const char gpen
return false;
}
ToolSettings *ts = CTX_data_tool_settings(C);
const ToolSettings *ts = CTX_data_tool_settings(C);
if (!ts || !ts->gp_paint) {
return false;
}
Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
const Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
return ((gpd->flag & GP_DATA_STROKE_PAINTMODE) && (brush && brush->gpencil_settings) &&
WM_toolsystem_active_tool_is_brush(C) &&
(brush->gpencil_brush_type == gpencil_brush_type));
@@ -86,17 +86,17 @@ static bool gpencil_stroke_paintmode_poll_with_tool(bContext *C, const char gpen
static bool gpencil_stroke_vertexmode_poll_with_tool(bContext *C,
const char gpencil_vertex_brush_type)
{
bGPdata *gpd = CTX_data_gpencil_data(C);
const bGPdata *gpd = CTX_data_gpencil_data(C);
if (!gpd) {
return false;
}
ToolSettings *ts = CTX_data_tool_settings(C);
const ToolSettings *ts = CTX_data_tool_settings(C);
if (!ts || !ts->gp_vertexpaint) {
return false;
}
Brush *brush = BKE_paint_brush(&ts->gp_vertexpaint->paint);
const Brush *brush = BKE_paint_brush(&ts->gp_vertexpaint->paint);
return ((gpd->flag & GP_DATA_STROKE_VERTEXMODE) && (brush && brush->gpencil_settings) &&
WM_toolsystem_active_tool_is_brush(C) &&
(brush->gpencil_vertex_brush_type == gpencil_vertex_brush_type));
@@ -105,17 +105,17 @@ static bool gpencil_stroke_vertexmode_poll_with_tool(bContext *C,
static bool gpencil_stroke_sculptmode_poll_with_tool(bContext *C,
const char gpencil_sculpt_brush_type)
{
bGPdata *gpd = CTX_data_gpencil_data(C);
const bGPdata *gpd = CTX_data_gpencil_data(C);
if (!gpd) {
return false;
}
ToolSettings *ts = CTX_data_tool_settings(C);
const ToolSettings *ts = CTX_data_tool_settings(C);
if (!ts || !ts->gp_sculptpaint) {
return false;
}
Brush *brush = BKE_paint_brush(&ts->gp_sculptpaint->paint);
const Brush *brush = BKE_paint_brush(&ts->gp_sculptpaint->paint);
return ((gpd->flag & GP_DATA_STROKE_SCULPTMODE) && (brush && brush->gpencil_settings) &&
WM_toolsystem_active_tool_is_brush(C) &&
(brush->gpencil_sculpt_brush_type == gpencil_sculpt_brush_type));
@@ -124,17 +124,17 @@ static bool gpencil_stroke_sculptmode_poll_with_tool(bContext *C,
static bool gpencil_stroke_weightmode_poll_with_tool(bContext *C,
const char gpencil_weight_brush_type)
{
bGPdata *gpd = CTX_data_gpencil_data(C);
const bGPdata *gpd = CTX_data_gpencil_data(C);
if (!gpd) {
return false;
}
ToolSettings *ts = CTX_data_tool_settings(C);
const ToolSettings *ts = CTX_data_tool_settings(C);
if (!ts || !ts->gp_weightpaint) {
return false;
}
Brush *brush = BKE_paint_brush(&ts->gp_weightpaint->paint);
const Brush *brush = BKE_paint_brush(&ts->gp_weightpaint->paint);
return ((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) && (brush && brush->gpencil_settings) &&
WM_toolsystem_active_tool_is_brush(C) &&
(brush->gpencil_weight_brush_type == gpencil_weight_brush_type));

View File

@@ -2235,7 +2235,8 @@ static void template_search_buttons(const bContext *C,
{
uiBlock *block = uiLayoutGetBlock(layout);
uiRNACollectionSearch *search_data = &template_search.search_data;
StructRNA *type = RNA_property_pointer_type(&search_data->target_ptr, search_data->target_prop);
const StructRNA *type = RNA_property_pointer_type(&search_data->target_ptr,
search_data->target_prop);
const bool editable = RNA_property_editable(&search_data->target_ptr, search_data->target_prop);
PointerRNA active_ptr = RNA_property_pointer_get(&search_data->target_ptr,
search_data->target_prop);
@@ -6444,7 +6445,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
UI_block_emboss_set(block, previous_emboss);
}
static bool uiTemplateInputStatusAzone(uiLayout *layout, AZone *az, ARegion *region)
static bool uiTemplateInputStatusAzone(uiLayout *layout, const AZone *az, const ARegion *region)
{
if (az->type == AZONE_AREA) {
uiItemL(layout, nullptr, ICON_MOUSE_LMB_DRAG);

View File

@@ -223,7 +223,7 @@ void ED_screen_draw_edges(wmWindow *win)
}
}
static void screen_draw_area_drag_tip(int x, int y, ScrArea *source, const std::string &hint)
static void screen_draw_area_drag_tip(int x, int y, const ScrArea *source, const std::string &hint)
{
if (!U.experimental.use_docking) {
return;

View File

@@ -683,7 +683,7 @@ static bool region_poll(const bContext *C,
/**
* \return true if any region polling state changed, and a screen refresh is needed.
*/
static bool screen_regions_poll(bContext *C, wmWindow *win, bScreen *screen)
static bool screen_regions_poll(bContext *C, wmWindow *win, const bScreen *screen)
{
wmWindow *prev_win = CTX_wm_window(C);
ScrArea *prev_area = CTX_wm_area(C);

View File

@@ -271,7 +271,7 @@ static int render_border_exec(bContext *C, wmOperator *op)
/* calculate range */
if (rv3d->persp == RV3D_CAMOB) {
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &vb, false);
}
else {

View File

@@ -57,7 +57,7 @@ void viewzoom_modal_keymap(wmKeyConfig *keyconf)
* (coords compatible w/ #wmEvent.xy). Use when not nullptr.
*/
static void view_zoom_to_window_xy_camera(Scene *scene,
Depsgraph *depsgraph,
const Depsgraph *depsgraph,
View3D *v3d,
ARegion *region,
float dfac,

View File

@@ -872,7 +872,7 @@ void ED_undo_object_editmode_restore_helper(Scene *scene,
((ID *)obedit->data)->tag &= ~ID_TAG_DOIT;
}
for (Base *base : bases) {
ID *id = static_cast<ID *>(base->object->data);
const ID *id = static_cast<ID *>(base->object->data);
if (id->tag & ID_TAG_DOIT) {
object::editmode_exit_ex(bmain, scene, base->object, object::EM_FREEDATA);
/* Ideally we would know the selection state it was before entering edit-mode,

View File

@@ -1433,7 +1433,7 @@ static int convertABGR_RGBA(const float *src,
static int convertCbYCr_RGBA(const float *src,
float *dst,
LogImageFile *logImage,
const LogImageFile *logImage,
const LogImageElement &logElement)
{
uint i;
@@ -1465,7 +1465,7 @@ static int convertCbYCr_RGBA(const float *src,
static int convertCbYCrA_RGBA(const float *src,
float *dst,
LogImageFile *logImage,
const LogImageFile *logImage,
const LogImageElement &logElement)
{
uint i;
@@ -1498,7 +1498,7 @@ static int convertCbYCrA_RGBA(const float *src,
static int convertCbYCrY_RGBA(const float *src,
float *dst,
LogImageFile *logImage,
const LogImageFile *logImage,
const LogImageElement &logElement)
{
uint i;
@@ -1550,7 +1550,7 @@ static int convertCbYCrY_RGBA(const float *src,
static int convertCbYACrYA_RGBA(const float *src,
float *dst,
LogImageFile *logImage,
const LogImageFile *logImage,
const LogImageElement &logElement)
{
uint i;
@@ -1604,7 +1604,7 @@ static int convertCbYACrYA_RGBA(const float *src,
static int convertLuminance_RGBA(const float *src,
float *dst,
LogImageFile *logImage,
const LogImageFile *logImage,
const LogImageElement &logElement)
{
uint i;
@@ -1630,7 +1630,7 @@ static int convertLuminance_RGBA(const float *src,
static int convertYA_RGBA(const float *src,
float *dst,
LogImageFile *logImage,
const LogImageFile *logImage,
const LogImageElement &logElement)
{
uint i;

View File

@@ -226,24 +226,24 @@ void RNA_api_pose(StructRNA *srna)
"pose of selected bones, or all bones if none are selected.");
parm = RNA_def_pointer(func, "action", "Action", "Action", "The Action containing the pose");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_float(func,
"blend_factor",
1.0f,
0.0f,
1.0f,
"Blend Factor",
"How much the given Action affects the final pose",
0.0f,
1.0f);
parm = RNA_def_float(func,
"evaluation_time",
0.0f,
-FLT_MAX,
FLT_MAX,
"Evaluation Time",
"Time at which the given action is evaluated to obtain the pose",
-FLT_MAX,
FLT_MAX);
RNA_def_float(func,
"blend_factor",
1.0f,
0.0f,
1.0f,
"Blend Factor",
"How much the given Action affects the final pose",
0.0f,
1.0f);
RNA_def_float(func,
"evaluation_time",
0.0f,
-FLT_MAX,
FLT_MAX,
"Evaluation Time",
"Time at which the given action is evaluated to obtain the pose",
-FLT_MAX,
FLT_MAX);
func = RNA_def_function(srna, "backup_create", "rna_Pose_backup_create");
RNA_def_function_ui_description(

View File

@@ -90,7 +90,7 @@
BPy_StructRNA *bpy_context_module = nullptr; /* for fast access */
static PyObject *pyrna_struct_CreatePyObject_from_type(PointerRNA *ptr,
static PyObject *pyrna_struct_CreatePyObject_from_type(const PointerRNA *ptr,
PyTypeObject *tp,
void **instance);
@@ -7624,7 +7624,7 @@ static PyObject *pyrna_struct_Subtype(PointerRNA *ptr)
* A lower level version of #pyrna_struct_CreatePyObject,
* use this when type (`tp`) needs to be set to a non-standard value.
*/
static PyObject *pyrna_struct_CreatePyObject_from_type(PointerRNA *ptr,
static PyObject *pyrna_struct_CreatePyObject_from_type(const PointerRNA *ptr,
PyTypeObject *tp,
void **instance)
{

View File

@@ -2230,7 +2230,7 @@ static ImBuf *do_speed_effect(const SeqRenderData *context,
ImBuf *ibuf1,
ImBuf *ibuf2)
{
SpeedControlVars *s = (SpeedControlVars *)seq->effectdata;
const SpeedControlVars *s = (SpeedControlVars *)seq->effectdata;
SeqEffectHandle cross_effect = get_sequence_effect_impl(SEQ_TYPE_CROSS);
ImBuf *out;

View File

@@ -122,10 +122,10 @@ static bool seq_cache_hashcmp(const void *a_, const void *b_)
seq_cmp_render_data(&a->context, &b->context));
}
static float seq_cache_timeline_frame_to_frame_index(Scene *scene,
static float seq_cache_timeline_frame_to_frame_index(const Scene *scene,
const Sequence *seq,
float timeline_frame,
int type)
const float timeline_frame,
const int type)
{
/* With raw images, map timeline_frame to strip input media frame range. This means that static
* images or extended frame range of movies will only generate one cache entry. No special

View File

@@ -360,7 +360,7 @@ static void color_balance_byte(const float cb_tab[3][CB_TABLE_SIZE],
int height)
{
uchar *ptr = rect;
uchar *ptr_end = ptr + int64_t(width) * height * 4;
const uchar *ptr_end = ptr + int64_t(width) * height * 4;
const uchar *mask_ptr = mask_rect;
if (mask_ptr != nullptr) {
@@ -975,7 +975,7 @@ static void brightcontrast_apply(const StripScreenQuad & /*quad*/,
ImBuf *ibuf,
ImBuf *mask)
{
BrightContrastModifierData *bcmd = (BrightContrastModifierData *)smd;
const BrightContrastModifierData *bcmd = (BrightContrastModifierData *)smd;
BrightContrastThreadData data;
data.bright = bcmd->bright;

View File

@@ -204,7 +204,7 @@ static void image_size_to_thumb_size(int &r_width, int &r_height)
}
}
static ImBuf *make_thumb_for_image(Scene *scene, const ThumbnailCache::Request &request)
static ImBuf *make_thumb_for_image(const Scene *scene, const ThumbnailCache::Request &request)
{
ImBuf *ibuf = IMB_thumb_load_image(
request.file_path.c_str(), SEQ_THUMB_SIZE, nullptr, IMBThumbLoadFlags::LoadLargeFiles);

View File

@@ -1538,7 +1538,7 @@ std::string WM_drag_get_string_firstline(const wmDrag *drag);
/* Set OpenGL viewport and scissor. */
void wmViewport(const rcti *winrct);
void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct);
void wmWindowViewport(wmWindow *win);
void wmWindowViewport(const wmWindow *win);
/* OpenGL utilities with safety check. */
void wmOrtho2(float x1, float x2, float y1, float y2);

View File

@@ -1919,7 +1919,7 @@ static bool wm_main_playanim_intern(int argc, const char **argv, PlayArgs *args_
#ifdef WITH_AUDASPACE
g_audaspace.source = AUD_Sound_file(filepath);
if (!BLI_listbase_is_empty(&ps.picsbase)) {
ImBufAnim *anim_movie = static_cast<PlayAnimPict *>(ps.picsbase.first)->anim;
const ImBufAnim *anim_movie = static_cast<PlayAnimPict *>(ps.picsbase.first)->anim;
if (anim_movie) {
short frs_sec = 25;
float frs_sec_base = 1.0;

View File

@@ -71,7 +71,7 @@ void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct
GPU_matrix_identity_set();
}
void wmWindowViewport(wmWindow *win)
void wmWindowViewport(const wmWindow *win)
{
int width = WM_window_native_pixel_x(win);
int height = WM_window_native_pixel_y(win);