From 66803e44419e3ec4d2cbfe39b8fed41d108aab71 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 12 Aug 2025 02:46:51 +0000 Subject: [PATCH] Cleanup: use function style casts --- intern/guardedalloc/intern/mallocn_guarded_impl.cc | 2 +- source/blender/blenlib/intern/BLI_ghash.cc | 2 +- source/blender/blenlib/intern/BLI_kdopbvh.cc | 11 +++++------ source/blender/blenlib/intern/BLI_mempool.cc | 4 ++-- source/blender/blenlib/intern/polyfill_2d_beautify.cc | 2 +- source/blender/blenlib/intern/scanfill_utils.cc | 4 ++-- source/blender/blenlib/intern/string.cc | 6 +++--- source/blender/blenlib/intern/time.cc | 2 +- .../editors/transform/transform_convert_sequencer.cc | 2 +- .../editors/transform/transform_snap_sequencer.cc | 2 +- source/blender/makesrna/intern/rna_ui.cc | 2 +- source/blender/makesrna/intern/rna_usd.cc | 2 +- source/blender/makesrna/intern/rna_wm.cc | 2 +- source/blender/render/intern/engine.cc | 4 ++-- 14 files changed, 23 insertions(+), 24 deletions(-) diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.cc b/intern/guardedalloc/intern/mallocn_guarded_impl.cc index 966be293d07..bb0f1eb7c8a 100644 --- a/intern/guardedalloc/intern/mallocn_guarded_impl.cc +++ b/intern/guardedalloc/intern/mallocn_guarded_impl.cc @@ -363,7 +363,7 @@ void *MEM_guarded_dupallocN(const void *vmemh) } else { newp = MEM_guarded_mallocN_aligned( - memh->len, (size_t)memh->alignment, name, AllocationType::ALLOC_FREE); + memh->len, size_t(memh->alignment), name, AllocationType::ALLOC_FREE); } if (newp == nullptr) diff --git a/source/blender/blenlib/intern/BLI_ghash.cc b/source/blender/blenlib/intern/BLI_ghash.cc index cf37fc9cdcd..14376197474 100644 --- a/source/blender/blenlib/intern/BLI_ghash.cc +++ b/source/blender/blenlib/intern/BLI_ghash.cc @@ -859,7 +859,7 @@ void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfree void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) { - BLI_assert((int)gh->nentries == BLI_mempool_len(gh->entrypool)); + BLI_assert(int(gh->nentries) == BLI_mempool_len(gh->entrypool)); if (keyfreefp || valfreefp) { ghash_free_cb(gh, keyfreefp, valfreefp); } diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.cc b/source/blender/blenlib/intern/BLI_kdopbvh.cc index bbe7dda5a06..664d790e996 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.cc +++ b/source/blender/blenlib/intern/BLI_kdopbvh.cc @@ -483,14 +483,13 @@ static void bvhtree_info(BVHTree *tree) tree->branch_num + tree->leaf_num, tree->branch_num, tree->leaf_num); - printf( - "Memory per node = %ubytes\n", - (uint)(sizeof(BVHNode) + sizeof(BVHNode *) * tree->tree_type + sizeof(float) * tree->axis)); - printf("BV memory = %ubytes\n", (uint)MEM_allocN_len(tree->nodebv)); + printf("Memory per node = %ubytes\n", + uint(sizeof(BVHNode) + sizeof(BVHNode *) * tree->tree_type + sizeof(float) * tree->axis)); + printf("BV memory = %ubytes\n", uint(MEM_allocN_len(tree->nodebv))); printf("Total memory = %ubytes\n", - (uint)(sizeof(BVHTree) + MEM_allocN_len(tree->nodes) + MEM_allocN_len(tree->nodearray) + - MEM_allocN_len(tree->nodechild) + MEM_allocN_len(tree->nodebv))); + uint(sizeof(BVHTree) + MEM_allocN_len(tree->nodes) + MEM_allocN_len(tree->nodearray) + + MEM_allocN_len(tree->nodechild) + MEM_allocN_len(tree->nodebv))); bvhtree_print_tree(tree, tree->nodes[tree->leaf_num], 0); } diff --git a/source/blender/blenlib/intern/BLI_mempool.cc b/source/blender/blenlib/intern/BLI_mempool.cc index 677a3001731..97a9b1fc41d 100644 --- a/source/blender/blenlib/intern/BLI_mempool.cc +++ b/source/blender/blenlib/intern/BLI_mempool.cc @@ -354,8 +354,8 @@ BLI_mempool *BLI_mempool_create(uint esize, uint elem_num, uint pchunk, uint fla /* Ensure this is a power of 2, minus the rounding by element size. */ #if defined(USE_CHUNK_POW2) && !defined(NDEBUG) { - uint final_size = (uint)MEM_SIZE_OVERHEAD + (uint)sizeof(BLI_mempool_chunk) + pool->csize; - BLI_assert(((uint)power_of_2_max_u(final_size) - final_size) < pool->esize); + uint final_size = uint(MEM_SIZE_OVERHEAD) + uint(sizeof(BLI_mempool_chunk)) + pool->csize; + BLI_assert((uint(power_of_2_max_u(final_size)) - final_size) < pool->esize); } #endif diff --git a/source/blender/blenlib/intern/polyfill_2d_beautify.cc b/source/blender/blenlib/intern/polyfill_2d_beautify.cc index f60358daee5..0e0387d186f 100644 --- a/source/blender/blenlib/intern/polyfill_2d_beautify.cc +++ b/source/blender/blenlib/intern/polyfill_2d_beautify.cc @@ -424,7 +424,7 @@ void BLI_polyfill_beautify(const float (*coords)[2], /* Now perform iterative rotations. */ #if 0 - eheap_table = BLI_memarena_alloc(arena, sizeof(HeapNode *) * (size_t)edges_len); + eheap_table = BLI_memarena_alloc(arena, sizeof(HeapNode *) * size_t(edges_len)); #else /* We can re-use this since its big enough. */ eheap_table = (HeapNode **)order_edges; diff --git a/source/blender/blenlib/intern/scanfill_utils.cc b/source/blender/blenlib/intern/scanfill_utils.cc index 93915a8ed1d..6e37b19d80a 100644 --- a/source/blender/blenlib/intern/scanfill_utils.cc +++ b/source/blender/blenlib/intern/scanfill_utils.cc @@ -49,7 +49,7 @@ struct ScanFillIsect { # define EFLAG_CLEAR(eed, val) \ { \ CHECK_TYPE(eed, ScanFillEdge *); \ - (eed)->user_flag = (eed)->user_flag & ~(uint)val; \ + (eed)->user_flag = (eed)->user_flag & ~uint(val); \ } \ (void)0 #endif @@ -64,7 +64,7 @@ struct ScanFillIsect { # define VFLAG_CLEAR(eve, val) \ { \ CHECK_TYPE(eve, ScanFillVert *); \ - (eve)->user_flags = (eve)->user_flag & ~(uint)val; \ + (eve)->user_flags = (eve)->user_flag & ~uint(val); \ } \ (void)0 #endif diff --git a/source/blender/blenlib/intern/string.cc b/source/blender/blenlib/intern/string.cc index 93383f7b3a3..5b3af4adb86 100644 --- a/source/blender/blenlib/intern/string.cc +++ b/source/blender/blenlib/intern/string.cc @@ -250,7 +250,7 @@ char *BLI_sprintfN_with_buffer( va_start(args, format); retval = vsnprintf(result, size, format, args); va_end(args); - BLI_assert((size_t)(retval + 1) == size); + BLI_assert(size_t(retval + 1) == size); UNUSED_VARS_NDEBUG(retval); return result; } @@ -283,7 +283,7 @@ char *BLI_vsprintfN_with_buffer(char *fixed_buf, const size_t size = size_t(retval) + 1; char *result = MEM_malloc_arrayN(size, __func__); retval = vsnprintf(result, size, format, args); - BLI_assert((size_t)(retval + 1) == size); + BLI_assert(size_t(retval + 1) == size); UNUSED_VARS_NDEBUG(retval); return result; } @@ -508,7 +508,7 @@ char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict if (!BLI_str_quoted_substr_range(str, prefix, &start_match_ofs, &end_match_ofs)) { return nullptr; } - const size_t escaped_len = (size_t)(end_match_ofs - start_match_ofs); + const size_t escaped_len = size_t(end_match_ofs - start_match_ofs); char *result = MEM_malloc_arrayN(escaped_len + 1, __func__); const size_t unescaped_len = BLI_str_unescape(result, str + start_match_ofs, escaped_len); if (unescaped_len != escaped_len) { diff --git a/source/blender/blenlib/intern/time.cc b/source/blender/blenlib/intern/time.cc index ba9f7eb30bf..fc56d3eba0d 100644 --- a/source/blender/blenlib/intern/time.cc +++ b/source/blender/blenlib/intern/time.cc @@ -27,7 +27,7 @@ double BLI_time_now_seconds() if (hasperfcounter == -1) { __int64 ifreq; hasperfcounter = QueryPerformanceFrequency((LARGE_INTEGER *)&ifreq); - perffreq = (double)ifreq; + perffreq = double(ifreq); } if (hasperfcounter) { diff --git a/source/blender/editors/transform/transform_convert_sequencer.cc b/source/blender/editors/transform/transform_convert_sequencer.cc index 7dcf0968a62..67ab0de957a 100644 --- a/source/blender/editors/transform/transform_convert_sequencer.cc +++ b/source/blender/editors/transform/transform_convert_sequencer.cc @@ -861,7 +861,7 @@ bool transform_convert_sequencer_clamp(const TransInfo *t, float r_val[2]) /* Unconditional channel, retiming key, and handle clamping. Should never be ignored. */ if (BLI_rcti_clamp_pt_v(&ts->offset_clamp, val)) { - r_val[0] = static_cast(val[0]); + r_val[0] = float(val[0]); r_val[1] = float(val[1]); clamped = true; } diff --git a/source/blender/editors/transform/transform_snap_sequencer.cc b/source/blender/editors/transform/transform_snap_sequencer.cc index 6e61856eefc..af67878ed37 100644 --- a/source/blender/editors/transform/transform_snap_sequencer.cc +++ b/source/blender/editors/transform/transform_snap_sequencer.cc @@ -544,7 +544,7 @@ static bool snap_calc_timeline(TransInfo *t, const TransSeqSnapData *snap_data) return false; } - float2 best_offset(static_cast(best_target_frame - best_source_frame), 0.0f); + float2 best_offset(float(best_target_frame - best_source_frame), 0.0f); if (transform_convert_sequencer_clamp(t, best_offset)) { return false; } diff --git a/source/blender/makesrna/intern/rna_ui.cc b/source/blender/makesrna/intern/rna_ui.cc index 0f14051533d..f53e9833529 100644 --- a/source/blender/makesrna/intern/rna_ui.cc +++ b/source/blender/makesrna/intern/rna_ui.cc @@ -1245,7 +1245,7 @@ static StructRNA *rna_AssetShelf_register(Main *bmain, RPT_ERROR, "Registering asset shelf class: '%s' is too long, maximum length is %d", identifier, - (int)sizeof(shelf_type->idname)); + int(sizeof(shelf_type->idname))); return nullptr; } diff --git a/source/blender/makesrna/intern/rna_usd.cc b/source/blender/makesrna/intern/rna_usd.cc index 160c0889eb4..4bfabafbaff 100644 --- a/source/blender/makesrna/intern/rna_usd.cc +++ b/source/blender/makesrna/intern/rna_usd.cc @@ -73,7 +73,7 @@ static StructRNA *rna_USDHook_register(Main *bmain, "%s '%s' is too long, maximum length is %d", error_prefix, identifier, - (int)sizeof(dummy_hook.idname)); + int(sizeof(dummy_hook.idname))); return nullptr; } diff --git a/source/blender/makesrna/intern/rna_wm.cc b/source/blender/makesrna/intern/rna_wm.cc index 5712687660e..577a21a1542 100644 --- a/source/blender/makesrna/intern/rna_wm.cc +++ b/source/blender/makesrna/intern/rna_wm.cc @@ -845,7 +845,7 @@ static int rna_NDOFMotionEventData_progress_get(PointerRNA *ptr) { # ifdef WITH_INPUT_NDOF const wmNDOFMotionData &ndof = *static_cast(ptr->data); - return static_cast(ndof.progress); + return int(ndof.progress); # else UNUSED_VARS(ptr); return 0; diff --git a/source/blender/render/intern/engine.cc b/source/blender/render/intern/engine.cc index ef687a53fb8..ffc40e2fa73 100644 --- a/source/blender/render/intern/engine.cc +++ b/source/blender/render/intern/engine.cc @@ -534,8 +534,8 @@ void RE_engine_update_memory_stats(RenderEngine *engine, float mem_used, float m Render *re = engine->re; if (re) { - re->i.mem_used = (int)ceilf(mem_used); - re->i.mem_peak = (int)ceilf(mem_peak); + re->i.mem_used = int(ceilf(mem_used)); + re->i.mem_peak = int(ceilf(mem_peak)); } }