From 8ad6e5819dd86ca9a3c9a91f09a878a4dc27b740 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Thu, 23 Feb 2023 08:10:19 +0100 Subject: [PATCH 01/31] did small loop optimizations to source/blender/blenloader/intern/blend_validate.cc replaced postincrement for the varible i with preincrement --- source/blender/blenloader/intern/blend_validate.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/blenloader/intern/blend_validate.cc b/source/blender/blenloader/intern/blend_validate.cc index 7ac0a4fe1af..29934a8a516 100644 --- a/source/blender/blenloader/intern/blend_validate.cc +++ b/source/blender/blenloader/intern/blend_validate.cc @@ -44,7 +44,7 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports) ListBase *lbarray[INDEX_ID_MAX]; int i = set_listbasepointers(bmain, lbarray); - while (i--) { + while (--i) { for (ID *id = static_cast(lbarray[i]->first); id != nullptr; id = static_cast(id->next)) { if (ID_IS_LINKED(id)) { @@ -80,7 +80,7 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports) } i = set_listbasepointers(curmain, lbarray); - while (i--) { + while (--i) { ID *id = static_cast(lbarray[i]->first); if (id == nullptr) { continue; -- 2.30.2 From f72b93dc02d02845eeb77bc122e60a1d54e7bb23 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Thu, 23 Feb 2023 08:53:43 +0100 Subject: [PATCH 02/31] did some loop optimizations to source/blender/blenloader/intern/readblenentry.cc replaced some postincrement for the variable tot with preincrement replaced postincrement for the variable preview_index with predecrement in line 230 for larger optimization --- .../blenloader/intern/readblenentry.cc | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/source/blender/blenloader/intern/readblenentry.cc b/source/blender/blenloader/intern/readblenentry.cc index 6b59ef87cec..e8cd5df334c 100644 --- a/source/blender/blenloader/intern/readblenentry.cc +++ b/source/blender/blenloader/intern/readblenentry.cc @@ -135,7 +135,7 @@ LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh, } BLI_linklist_prepend(&names, BLI_strdup(idname + 2)); - tot++; + ++tot; } else if (bhead->code == ENDB) { break; @@ -200,7 +200,7 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh, info->no_preview_found = !has_preview; BLI_linklist_prepend(&infos, info); - tot++; + ++tot; } } @@ -227,25 +227,28 @@ static BHead *blo_blendhandle_read_preview_rects(FileData *fd, PreviewImage *result, const PreviewImage *preview_from_file) { - for (int preview_index = 0; preview_index < NUM_ICON_SIZES; preview_index++) { - if (preview_from_file->rect[preview_index] && preview_from_file->w[preview_index] && - preview_from_file->h[preview_index]) { + int change = 0; + for (int preview_index = NUM_ICON_SIZES; --preview_index) { + //changed it to use decrement instead of increment to use less resources + change = (NUM_ICON_SIZES - preview_index) + if (preview_from_file->rect[change] && preview_from_file->w[change] && + preview_from_file->h[change]) { bhead = blo_bhead_next(fd, bhead); - BLI_assert((preview_from_file->w[preview_index] * preview_from_file->h[preview_index] * + BLI_assert((preview_from_file->w[change] * preview_from_file->h[change] * sizeof(uint)) == bhead->len); - result->rect[preview_index] = static_cast( + result->rect[change] = static_cast( BLO_library_read_struct(fd, bhead, "PreviewImage Icon Rect")); } else { /* This should not be needed, but can happen in 'broken' .blend files, * better handle this gracefully than crashing. */ - BLI_assert(preview_from_file->rect[preview_index] == nullptr && - preview_from_file->w[preview_index] == 0 && - preview_from_file->h[preview_index] == 0); - result->rect[preview_index] = nullptr; - result->w[preview_index] = result->h[preview_index] = 0; + BLI_assert(preview_from_file->rect[change] == nullptr && + preview_from_file->w[change] == 0 && + preview_from_file->h[change] == 0); + result->rect[change] = nullptr; + result->w[change] = result->h[change] = 0; } - BKE_previewimg_finish(result, preview_index); + BKE_previewimg_finish(result, change); } return bhead; @@ -317,7 +320,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_ case ID_NT: /* fall through */ new_prv = static_cast(MEM_callocN(sizeof(PreviewImage), "newpreview")); BLI_linklist_prepend(&previews, new_prv); - tot++; + ++tot; looking = 1; break; default: -- 2.30.2 From b4fb43644b5053916772060e98704c7f4416e57e Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Thu, 23 Feb 2023 20:34:52 +0100 Subject: [PATCH 03/31] did some loop optimizations to source/blender/blenloader/intern/readfile.cc replaced postdecrement in some while loops with predecrement to save a small amount of resources replaced postincrement in some for loops with predecrement to save alot of resources --- source/blender/blenloader/intern/readfile.cc | 55 +++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index 29730f7f10a..38b11e52956 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -322,7 +322,7 @@ static void add_main_to_main(Main *mainvar, Main *from) set_listbasepointers(mainvar, lbarray); a = set_listbasepointers(from, fromarray); - while (a--) { + while (--a) { BLI_movelisttolist(lbarray[a], fromarray[a]); } } @@ -389,7 +389,7 @@ void blo_split_main(ListBase *mainlist, Main *main) int i = 0; for (Library *lib = static_cast(main->libraries.first); lib; - lib = static_cast(lib->id.next), i++) { + lib = static_cast(lib->id.next), ++i) { Main *libmain = BKE_main_new(); libmain->curlib = lib; libmain->versionfile = lib->versionfile; @@ -401,7 +401,7 @@ void blo_split_main(ListBase *mainlist, Main *main) ListBase *lbarray[INDEX_ID_MAX]; i = set_listbasepointers(main, lbarray); - while (i--) { + while (--i) { ID *id = static_cast(lbarray[i]->first); if (id == nullptr || GS(id->name) == ID_LI) { /* No ID_LI data-block should ever be linked anyway, but just in case, better be explicit. */ @@ -1556,7 +1556,7 @@ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd) LISTBASE_FOREACH (Main *, ptr, old_mainlist) { int i = set_listbasepointers(ptr, lbarray); - while (i--) { + while (--i) { LISTBASE_FOREACH (ID *, id, lbarray[i]) { oldnewmap_lib_insert(fd, id, id, GS(id->name)); } @@ -1750,7 +1750,7 @@ static void switch_endian_structs(const SDNA *filesdna, BHead *bhead) blocksize = filesdna->types_size[filesdna->structs[bhead->SDNAnr]->type]; nblocks = bhead->nr; - while (nblocks--) { + while (--nblocks) { DNA_struct_switch_endian(filesdna, bhead->SDNAnr, data); data += blocksize; @@ -2167,8 +2167,8 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene) return true; } - for (a = 0, sce_iter = sce; sce_iter->set; sce_iter = sce_iter->set, a++) { - /* This runs per library (before each libraries #Main has been joined), + for (a = 0, sce_iter = sce; sce_iter->set; sce_iter = sce_iter->set, ++a) { + /* This runs per library (before each libraries #Main has been joined), * so we can't step into other libraries since `totscene` is only for this library. * * Also, other libraries may not have been linked yet, @@ -4042,7 +4042,7 @@ static void sort_bhead_old_map(FileData *fd) int tot = 0; for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) { - tot++; + ++tot; } fd->tot_bheadmap = tot; @@ -4347,7 +4347,7 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) do_it = false; a = set_listbasepointers(mainvar, lbarray); - while (a--) { + while (--a) { id = static_cast(lbarray[a]->first); while (id) { if (id->tag & LIB_TAG_NEED_EXPAND) { @@ -4517,7 +4517,7 @@ static void split_main_newid(Main *mainptr, Main *main_newid) ListBase *lbarray_newid[INDEX_ID_MAX]; int i = set_listbasepointers(mainptr, lbarray); set_listbasepointers(main_newid, lbarray_newid); - while (i--) { + while (--i) { BLI_listbase_clear(lbarray_newid[i]); LISTBASE_FOREACH_MUTABLE (ID *, id, lbarray[i]) { @@ -4652,7 +4652,7 @@ static int has_linked_ids_to_read(Main *mainvar) ListBase *lbarray[INDEX_ID_MAX]; int a = set_listbasepointers(mainvar, lbarray); - while (a--) { + while (--a) { LISTBASE_FOREACH (ID *, id, lbarray[a]) { if ((id->tag & LIB_TAG_ID_LINK_PLACEHOLDER) && !(id->flag & LIB_INDIRECT_WEAK_LINK)) { return true; @@ -4721,7 +4721,7 @@ static void read_library_linked_ids(FileData *basefd, ListBase *lbarray[INDEX_ID_MAX]; int a = set_listbasepointers(mainvar, lbarray); - while (a--) { + while (--a) { ID *id = static_cast(lbarray[a]->first); ListBase pending_free_ids = {nullptr}; @@ -4773,7 +4773,7 @@ static void read_library_clear_weak_links(FileData *basefd, ListBase *mainlist, ListBase *lbarray[INDEX_ID_MAX]; int a = set_listbasepointers(mainvar, lbarray); - while (a--) { + while (--a) { ID *id = static_cast(lbarray[a]->first); while (id) { @@ -5072,15 +5072,25 @@ static void convert_pointer_array_64_to_32(BlendDataReader *reader, { /* Match pointer conversion rules from bh4_from_bh8 and cast_pointer. */ if (BLO_read_requires_endian_switch(reader)) { - for (int i = 0; i < array_size; i++) { - uint64_t ptr = src[i]; + int change = 0; + for (int i = array_size; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (array_size - i); + uint64_t ptr = src[change]; BLI_endian_switch_uint64(&ptr); - dst[i] = uint32_t(ptr >> 3); + dst[change] = uint32_t(ptr >> 3); } } else { - for (int i = 0; i < array_size; i++) { - dst[i] = uint32_t(src[i] >> 3); + int change = 0; + for (int i = array_size; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (array_size - i); + dst[change] = uint32_t(src[change] >> 3); } } } @@ -5091,8 +5101,13 @@ static void convert_pointer_array_32_to_64(BlendDataReader * /*reader*/, uint64_t *dst) { /* Match pointer conversion rules from bh8_from_bh4 and cast_pointer_32_to_64. */ - for (int i = 0; i < array_size; i++) { - dst[i] = src[i]; + int change = 0; + for (int i = array_size; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (array_size - i); + dst[change] = src[change]; } } -- 2.30.2 From 2dc3051d354fff2c46a56503ed5ede2291b75dd5 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Fri, 24 Feb 2023 00:33:55 +0100 Subject: [PATCH 04/31] did large loop optimizations to source/blender/blenloader/intern/versioning_250.c replaced postincrement in some for loops with predecrement to save alot of resources --- .../blenloader/intern/versioning_250.c | 69 ++++++++++++++----- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index fb806a0b124..74cba2333bb 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -823,10 +823,15 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (ob->totcol && ob->matbits == NULL) { int a; + int change; ob->matbits = MEM_calloc_arrayN(ob->totcol, sizeof(char), "ob->matbits"); - for (a = 0; a < ob->totcol; a++) { - ob->matbits[a] = (ob->colbits & (1 << a)) != 0; + for (a = ob->totcol; --a) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (ob->totcol - a) + ob->matbits[change] = (ob->colbits & (1 << change)) != 0; } } } @@ -987,7 +992,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) Curve *cu; Key *key; const float *data; - int a, tot; + int a, tot, change; /* shape keys are no longer applied to the mesh itself, but rather * to the evaluated #Mesh, so here we ensure that the basis @@ -997,8 +1002,12 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) data = key->refkey->data; tot = MIN2(me->totvert, key->refkey->totelem); MVert *verts = (MVert *)CustomData_get_layer_for_write(&me->vdata, CD_MVERT, me->totvert); - for (a = 0; a < tot; a++, data += 3) { - copy_v3_v3(verts[a].co_legacy, data); + for (a = tot; --a, data += 3) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (tot - a) + copy_v3_v3(verts[change].co_legacy, data); } } } @@ -1008,8 +1017,12 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) data = key->refkey->data; tot = MIN2(lt->pntsu * lt->pntsv * lt->pntsw, key->refkey->totelem); - for (a = 0; a < tot; a++, data += 3) { - copy_v3_v3(lt->def[a].vec, data); + for (a = tot; --a, data += 3) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (tot - a) + copy_v3_v3(lt->def[change].vec, data); } } } @@ -1022,7 +1035,10 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (nu->bezt) { BezTriple *bezt = nu->bezt; - for (a = 0; a < nu->pntsu; a++, bezt++) { + for (a = nu->pntsu; --a, bezt++) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ copy_v3_v3(bezt->vec[0], data); data += 3; copy_v3_v3(bezt->vec[1], data); @@ -1030,17 +1046,20 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) copy_v3_v3(bezt->vec[2], data); data += 3; bezt->tilt = *data; - data++; + ++data; } } else if (nu->bp) { BPoint *bp = nu->bp; - for (a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) { + for (a = nu->pntsu * nu->pntsv; --a, ++bp) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ copy_v3_v3(bp->vec, data); data += 3; bp->tilt = *data; - data++; + ++data; } } } @@ -1422,10 +1441,14 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) /* particle brush strength factor was changed from int to float */ for (sce = bmain->scenes.first; sce; sce = sce->id.next) { ParticleEditSettings *pset = &sce->toolsettings->particle; - int a; + int a, change; - for (a = 0; a < ARRAY_SIZE(pset->brush); a++) { - pset->brush[a].strength /= 100.0f; + for (a = ARRAY_SIZE(pset->brush); --a) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (ARRAY_SIZE(pset->brush) - a) + pset->brush[change].strength /= 100.0f; } } @@ -1659,10 +1682,14 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) /* initialize scene active layer */ for (scene = bmain->scenes.first; scene; scene = scene->id.next) { - int i; - for (i = 0; i < 20; i++) { - if (scene->lay & (1 << i)) { - scene->layact = 1 << i; + int i, change; + for (i = 20; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (20 - i); + if (scene->lay & (1 << change)) { + scene->layact = 1 << change; break; } } @@ -2223,6 +2250,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) for (fcu = act->curves.first; fcu; fcu = fcu->next) { BezTriple *bezt; uint i = 0; + uint change = 0; /* only need to touch curves that had this flag set */ if ((fcu->flag & FCURVE_AUTO_HANDLES) == 0) { @@ -2233,7 +2261,10 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } /* only change auto-handles to auto-clamped */ - for (bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { + for (bezt = fcu->bezt; i = fcu->totvert; --i, ++bezt) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ if (bezt->h1 == HD_AUTO) { bezt->h1 = HD_AUTO_ANIM; } -- 2.30.2 From 8ab10a88c226bd4fbb09cd021bd97a9980f9467a Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Fri, 24 Feb 2023 01:02:39 +0100 Subject: [PATCH 05/31] did some loop optimizations to source/blender/blenloader/intern/readblenentry.cc replaced postfix in some while loops and if statements with prefix to save a smalll amount of resorces replaced postincrement in some for loops with predecrement to save alot of resources --- .../blenloader/intern/versioning_260.c | 50 +++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index 0a4211315c0..d64ed955737 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -353,13 +353,23 @@ static void do_versions_mesh_mloopcol_swap_2_62_1(Mesh *me) MLoopCol *mloopcol; int a; int i; + int change1; + int change2; - for (a = 0; a < me->ldata.totlayer; a++) { + for (a = me->ldata.totlayer; --a) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change1 = (me->ldata.totlayer - a); layer = &me->ldata.layers[a]; if (layer->type == CD_PROP_BYTE_COLOR) { mloopcol = (MLoopCol *)layer->data; - for (i = 0; i < me->totloop; i++, mloopcol++) { + for (i = me->totloop; --i, ++mloopcol) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change2 = (me->totloop - i); SWAP(uchar, mloopcol->r, mloopcol->b); } } @@ -450,9 +460,14 @@ static void do_versions_nodetree_frame_2_64_6(bNodeTree *ntree) static void do_versions_affine_tracker_track(MovieTrackingTrack *track) { int i; + int change; - for (i = 0; i < track->markersnr; i++) { - MovieTrackingMarker *marker = &track->markers[i]; + for (i = track->markersnr; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (track->markersnr - i); + MovieTrackingMarker *marker = &track->markers[change]; if (is_zero_v2(marker->pattern_corners[0]) && is_zero_v2(marker->pattern_corners[1]) && is_zero_v2(marker->pattern_corners[2]) && is_zero_v2(marker->pattern_corners[3])) { @@ -892,15 +907,20 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (ob = bmain->objects.first; ob; ob = ob->id.next) { /* convert delta addition into delta scale */ int i; - for (i = 0; i < 3; i++) { - if ((ob->dsize[i] == 0.0f) || /* simple case, user never touched dsize */ - (ob->scale[i] == 0.0f)) /* can't scale the dsize to give a non zero result, + int change; + for (i = 3; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (3 - i) + if ((ob->dsize[change] == 0.0f) || /* simple case, user never touched dsize */ + (ob->scale[change] == 0.0f)) /* can't scale the dsize to give a non zero result, * so fallback to 1.0f */ { - ob->dscale[i] = 1.0f; + ob->dscale[change] = 1.0f; } else { - ob->dscale[i] = (ob->scale[i] + ob->dsize[i]) / ob->scale[i]; + ob->dscale[change] = (ob->scale[change] + ob->dsize[change]) / ob->scale[change]; } } } @@ -1863,18 +1883,18 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) BezTriple *bezt = nu->bezt; a = nu->pntsu; - while (a--) { + while (--a) { bezt->radius = 1.0f; - bezt++; + ++bezt; } } else if (nu->bp) { BPoint *bp = nu->bp; a = nu->pntsu * nu->pntsv; - while (a--) { + while (--a) { bp->radius = 1.0f; - bp++; + ++bp; } } } @@ -2606,7 +2626,7 @@ void do_versions_after_linking_260(Main *bmain) if (input_node) { link->fromnode = input_node; link->fromsock = node_group_input_find_socket(input_node, link->fromsock->identifier); - num_inputs++; + ++num_inputs; if (link->tonode) { if (input_locx > link->tonode->locx - offsetx) { @@ -2624,7 +2644,7 @@ void do_versions_after_linking_260(Main *bmain) if (output_node) { link->tonode = output_node; link->tosock = node_group_output_find_socket(output_node, link->tosock->identifier); - num_outputs++; + ++num_outputs; if (link->fromnode) { if (output_locx < link->fromnode->locx + offsetx) { -- 2.30.2 From b6cafca9f1ed66a9c6a1f2215a3e87f1d42b920a Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Sun, 26 Feb 2023 22:37:05 +0100 Subject: [PATCH 06/31] did big loop optimizations to source/blender/blenloader/intern/versioning_270.c replaced a postdecrement in a while loop with predecrement to save a small amount of resources replaced postincrement in some for loops with predecrement to save a large amount of resources --- .../blenloader/intern/versioning_270.c | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 067918976c7..76dbb1f4c70 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -809,8 +809,13 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) ParticleSettings *part; for (part = bmain->particles.first; part; part = part->id.next) { int a; - for (a = 0; a < MAX_MTEX; a++) { - MTex *mtex = part->mtex[a]; + int change + for (a = MAX_MTEX; --a) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (MAX_MTEX - a) + MTex *mtex = part->mtex[change]; if (mtex) { mtex->kinkampfac = 1.0f; } @@ -1147,7 +1152,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) /* Important to clear all non-persistent flags from older versions here, * otherwise they could collide with any new persistent flag we may add in the future. */ a = set_listbasepointers(bmain, lbarray); - while (a--) { + while (--a) { LISTBASE_FOREACH (ID *, id, lbarray[a]) { id->flag &= LIB_FAKEUSER; } @@ -1165,8 +1170,11 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { ParticleEditSettings *pset = &scene->toolsettings->particle; for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) { - if (pset->brush[a].strength > 1.0f) { - pset->brush[a].strength *= 0.01f; + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + if (pset->brush[change].strength > 1.0f) { + pset->brush[change].strength *= 0.01f; } } } @@ -1374,8 +1382,13 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) gps->thickness = gpl->thickness; /* set alpha strength to 1 */ - for (int i = 0; i < gps->totpoints; i++) { - gps->points[i].strength = 1.0f; + int change; + for (int i = gps->totpoints; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (gps->totpoints - i); + gps->points[change].strength = 1.0f; } } } @@ -1463,9 +1476,14 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) if (scene->toolsettings != NULL) { ToolSettings *ts = scene->toolsettings; ParticleEditSettings *pset = &ts->particle; - for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) { - if (pset->brush[a].count == 0) { - pset->brush[a].count = 10; + int change; + for (int a = ARRAY_SIZE(pset->brush); --a) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (ARRAY_SIZE(pset->brush) - a) + if (pset->brush[change].count == 0) { + pset->brush[change].count = 10; } } } @@ -1646,8 +1664,13 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { ToolSettings *ts = scene->toolsettings; - for (int i = 0; i < 2; i++) { - VPaint *vp = i ? ts->vpaint : ts->wpaint; + int change; + for (int i = 2; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (2 - i); + VPaint *vp = change ? ts->vpaint : ts->wpaint; if (vp != NULL) { /* remove all other flags */ vp->flag &= (VP_FLAG_VGROUP_RESTRICT); -- 2.30.2 From 6b01dea3521378c2f00e98953f728965d5d0efc6 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 27 Feb 2023 20:29:35 +0100 Subject: [PATCH 07/31] did large loop optimizations to source/blender/blenloader/intern/versioning_280.c replaced the postincrement in some for loops with predecrement to save alot of resources --- .../blenloader/intern/versioning_280.c | 87 ++++++++++++++----- 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index ff860677663..b70f90f653c 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -423,31 +423,36 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) Collection *collection_master = scene->master_collection; Collection *collections[20] = {NULL}; - for (int layer = 0; layer < 20; layer++) { + int change; + for (int layer = 20; --layer) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (20 - layer); LISTBASE_FOREACH (Base *, base, &scene->base) { - if (base->lay & (1 << layer)) { + if (base->lay & (1 << change)) { /* Create collections when needed only. */ - if (collections[layer] == NULL) { + if (collections[change] == NULL) { char name[MAX_NAME]; BLI_snprintf( - name, sizeof(collection_master->id.name), DATA_("Collection %d"), layer + 1); + name, sizeof(collection_master->id.name), DATA_("Collection %d"), change + 1); Collection *collection = BKE_collection_add(bmain, collection_master, name); collection->id.lib = scene->id.lib; if (ID_IS_LINKED(collection)) { collection->id.tag |= LIB_TAG_INDIRECT; } - collections[layer] = collection; + collections[change] = collection; - if (!(scene->lay & (1 << layer))) { + if (!(scene->lay & (1 << change))) { collection->flag |= COLLECTION_HIDE_VIEWPORT | COLLECTION_HIDE_RENDER; } } /* Note usually this would do slow collection syncing for view layers, * but since no view layers exists yet at this point it's fast. */ - BKE_collection_object_add_notest(bmain, collections[layer], base->object); + BKE_collection_object_add_notest(bmain, collections[change], base->object); } if (base->flag & SELECT) { @@ -485,13 +490,18 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) view_layer->id_properties = srl->prop; /* Set exclusion and overrides. */ - for (int layer = 0; layer < 20; layer++) { - Collection *collection = collections[layer]; + int change; + for (int layer = 20; --layer) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (20 - layer); + Collection *collection = collections[change]; if (collection) { LayerCollection *lc = BKE_layer_collection_first_from_scene_collection(view_layer, collection); - if (srl->lay_exclude & (1 << layer)) { + if (srl->lay_exclude & (1 << change)) { /* Disable excluded layer. */ have_override = true; lc->flag |= LAYER_COLLECTION_EXCLUDE; @@ -500,12 +510,12 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) } } else { - if (srl->lay_zmask & (1 << layer)) { + if (srl->lay_zmask & (1 << change)) { have_override = true; lc->flag |= LAYER_COLLECTION_HOLDOUT; } - if ((srl->lay & (1 << layer)) == 0) { + if ((srl->lay & (1 << change)) == 0) { have_override = true; lc->flag |= LAYER_COLLECTION_INDIRECT_ONLY; } @@ -901,8 +911,13 @@ static void do_version_curvemapping_flag_extend_extrapolate(CurveMapping *cumap) } #define CUMA_EXTEND_EXTRAPOLATE_OLD 1 - for (int curve_map_index = 0; curve_map_index < 4; curve_map_index++) { - CurveMap *cuma = &cumap->cm[curve_map_index]; + int change; + for (int curve_map_index = 4; --curve_map_index) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (4 - curve_map_index); + CurveMap *cuma = &cumap->cm[change]; if (cuma->flag & CUMA_EXTEND_EXTRAPOLATE_OLD) { cumap->flag |= CUMA_EXTEND_EXTRAPOLATE; return; @@ -1198,9 +1213,14 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) /* Find or create hidden collection matching object's first layer. */ Collection **collection_hidden = NULL; int coll_idx = 0; - for (; coll_idx < 20; coll_idx++) { - if (ob->lay & (1 << coll_idx)) { - collection_hidden = &hidden_collection_array[coll_idx]; + int change = 0; + for (coll_idx= 20; --coll_idx) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (20 - coll_idx); + if (ob->lay & (1 << change)) { + collection_hidden = &hidden_collection_array[change]; break; } } @@ -1433,7 +1453,10 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) if (nu->bezt) { BezTriple *bezt = nu->bezt; - for (int a = 0; a < nu->pntsu; a++, bezt++) { + for (int a = nu->pntsu; --a, ++bezt) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ if ((old_count -= 3) < 0) { memcpy(newptr, bezt->vec, sizeof(float[3][3])); newptr[3][0] = bezt->tilt; @@ -1451,7 +1474,10 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) else if (nu->bp) { BPoint *bp = nu->bp; - for (int a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) { + for (int a = nu->pntsu * nu->pntsv; --a, ++bp) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ if (--old_count < 0) { copy_v3_v3(newptr[0], bp->vec); newptr[1][0] = bp->tilt; @@ -2558,9 +2584,14 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!DNA_struct_elem_find(fd->filesdna, "Image", "ListBase", "renderslot")) { for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { if (ima->type == IMA_TYPE_R_RESULT) { - for (int i = 0; i < 8; i++) { + int change; + for (int i = 8; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (8 - i); RenderSlot *slot = MEM_callocN(sizeof(RenderSlot), "Image Render Slot Init"); - BLI_snprintf(slot->name, sizeof(slot->name), "Slot %d", i + 1); + BLI_snprintf(slot->name, sizeof(slot->name), "Slot %d", change + 1); BLI_addtail(&ima->renderslots, slot); } } @@ -3498,8 +3529,13 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!DNA_struct_find(fd->filesdna, "TransformOrientationSlot")) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - for (int i = 0; i < ARRAY_SIZE(scene->orientation_slots); i++) { - scene->orientation_slots[i].index_custom = -1; + int change; + for (int i = ARRAY_SIZE(scene->orientation_slots); --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (ARRAY_SIZE(scene->orientation_slots) - i); + scene->orientation_slots[change].index_custom = -1; } } } @@ -4837,7 +4873,10 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) srgb_to_linearrgb_v4(gps->vert_color_fill, gps->vert_color_fill); int i; bGPDspoint *pt; - for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + for (i = gps->totpoints, pt = gps->points;--i, ++pt) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ srgb_to_linearrgb_v4(pt->vert_color, pt->vert_color); } } -- 2.30.2 From c09454265f1bfa9fdd6c36bc4b9d959c7812e635 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Tue, 28 Feb 2023 23:16:49 +0100 Subject: [PATCH 08/31] did large loop optimizations to source/blender/blenloader/intern/versioning_290.cc replaced postincrement in some for loops with predecrement to save lot of resources --- .../blenloader/intern/versioning_290.cc | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_290.cc b/source/blender/blenloader/intern/versioning_290.cc index b90e7529bbc..1c4ee5efc97 100644 --- a/source/blender/blenloader/intern/versioning_290.cc +++ b/source/blender/blenloader/intern/versioning_290.cc @@ -706,8 +706,13 @@ static void do_versions_point_attributes(CustomData *pdata) CD_RADIUS = 44, }; - for (int i = 0; i < pdata->totlayer; i++) { - CustomDataLayer *layer = &pdata->layers[i]; + int change; + for (int i = pdata->totlayer; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (pdata->totlayer - i); + CustomDataLayer *layer = &pdata->layers[change]; if (layer->type == CD_LOCATION) { STRNCPY(layer->name, "Position"); layer->type = CD_PROP_FLOAT3; @@ -722,8 +727,12 @@ static void do_versions_point_attributes(CustomData *pdata) static void do_versions_point_attribute_names(CustomData *pdata) { /* Change from capital initial letter to lower case (#82693). */ - for (int i = 0; i < pdata->totlayer; i++) { - CustomDataLayer *layer = &pdata->layers[i]; + for (int i = pdata->totlayer; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (pdata->totlayer - i); + CustomDataLayer *layer = &pdata->layers[change]; if (layer->type == CD_PROP_FLOAT3 && STREQ(layer->name, "Position")) { STRNCPY(layer->name, "position"); } @@ -739,8 +748,11 @@ static void do_versions_point_attribute_names(CustomData *pdata) * This function applies the old correction to the actual animation data instead. */ static void do_versions_291_fcurve_handles_limit(FCurve *fcu) { - uint i = 1; - for (BezTriple *bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { + uint i = (fcu->totvert - 1); + for (BezTriple *bezt = fcu->bezt; --i, ++bezt) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ /* Only adjust bezier key-frames. */ if (bezt->ipo != BEZT_IPO_BEZ) { continue; @@ -845,8 +857,13 @@ void blo_do_versions_290(FileData *fd, Library * /*lib*/, Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 290, 2)) { { short id_codes[] = {ID_BR, ID_PAL}; - for (int i = 0; i < ARRAY_SIZE(id_codes); i++) { - ListBase *lb = which_libbase(bmain, id_codes[i]); + int change; + for (int i = ARRAY_SIZE(id_codes); --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (ARRAY_SIZE(id_codes) - i); + ListBase *lb = which_libbase(bmain, id_codes[change]); BKE_main_id_repair_duplicate_names_listbase(bmain, lb); } } @@ -1667,7 +1684,7 @@ void blo_do_versions_290(FileData *fd, Library * /*lib*/, Main *bmain) LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) { /* Enable Outliner render visibility column. */ - if (space->spacetype == SPACE_OUTLINER) { + if (space->spacetype == SPACE_OUTLINER) {21 SpaceOutliner *space_outliner = (SpaceOutliner *)space; space_outliner->show_restrict_flags |= SO_RESTRICT_RENDER; } -- 2.30.2 From c440322780ddc08bf4153203a9c5b7c56f5246a6 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Fri, 3 Mar 2023 00:28:37 +0100 Subject: [PATCH 09/31] did more large loop optimizations to source/blender/blenloader/intern/versioning_290.cc i missed some for loops and replaced their postincrement with predecrement --- source/blender/blenloader/intern/versioning_290.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_290.cc b/source/blender/blenloader/intern/versioning_290.cc index 1c4ee5efc97..e498f08775a 100644 --- a/source/blender/blenloader/intern/versioning_290.cc +++ b/source/blender/blenloader/intern/versioning_290.cc @@ -122,7 +122,11 @@ static void seq_convert_transform_animation(const Sequence *seq, FCurve *fcu = BKE_fcurve_find(&scene->adt->action->curves, path, 0); if (fcu != nullptr && !BKE_fcurve_is_empty(fcu)) { BezTriple *bezt = fcu->bezt; - for (int i = 0; i < fcu->totvert; i++, bezt++) { + int change; + for (int i = fcu->totvert; --i, ++bezt) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ /* Same math as with old_image_center_*, but simplified. */ bezt->vec[0][1] = (image_size - scene_size) / 2 + bezt->vec[0][1]; bezt->vec[1][1] = (image_size - scene_size) / 2 + bezt->vec[1][1]; @@ -271,7 +275,11 @@ static void seq_convert_transform_animation_2(const Scene *scene, FCurve *fcu = BKE_fcurve_find(&scene->adt->action->curves, path, 0); if (fcu != nullptr && !BKE_fcurve_is_empty(fcu)) { BezTriple *bezt = fcu->bezt; - for (int i = 0; i < fcu->totvert; i++, bezt++) { + int change; + for (int i = fcu->totvert; --i, ++bezt) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ /* Same math as with old_image_center_*, but simplified. */ bezt->vec[0][1] *= scale_to_fit_factor; bezt->vec[1][1] *= scale_to_fit_factor; @@ -1684,7 +1692,7 @@ void blo_do_versions_290(FileData *fd, Library * /*lib*/, Main *bmain) LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) { /* Enable Outliner render visibility column. */ - if (space->spacetype == SPACE_OUTLINER) {21 + if (space->spacetype == SPACE_OUTLINER) { SpaceOutliner *space_outliner = (SpaceOutliner *)space; space_outliner->show_restrict_flags |= SO_RESTRICT_RENDER; } -- 2.30.2 From 664d0e5765f85b3a8b9ff0802e715f8bfb2b3970 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 13 Mar 2023 21:52:32 +0100 Subject: [PATCH 10/31] did large loop optimizations to source/blender/blenloader/intern/versioning_300.cc replaced the postincrement in some for loops with predecrement to save resources --- .../blenloader/intern/versioning_300.cc | 71 ++++++++++++++----- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index 4a1c14bd430..ef1b02068ef 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -173,8 +173,13 @@ static void version_idproperty_move_data_float(IDPropertyUIDataFloat *ui_data, ui_data->default_array = static_cast( MEM_malloc_arrayN(array_len, sizeof(double), __func__)); const float *old_default_array = static_cast(IDP_Array(default_value)); - for (int i = 0; i < ui_data->default_array_len; i++) { - ui_data->default_array[i] = double(old_default_array[i]); + int change; + for (int i = ui_data->default_array_len; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (ui_data->default_array_len - i); + ui_data->default_array[change] = double(old_default_array[change]); } } else if (default_value->subtype == IDP_DOUBLE) { @@ -483,7 +488,10 @@ static bool do_versions_sequencer_color_balance_sop(Sequence *seq, void * /*user if (smd->type == seqModifierType_ColorBalance) { StripColorBalance *cb = &((ColorBalanceModifierData *)smd)->color_balance; cb->method = SEQ_COLOR_BALANCE_METHOD_LIFTGAMMAGAIN; - for (int i = 0; i < 3; i++) { + for (int i = 3; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ copy_v3_fl(cb->slope, 1.0f); copy_v3_fl(cb->offset, 1.0f); copy_v3_fl(cb->power, 1.0f); @@ -2300,8 +2308,13 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) if (smd->bind_verts_num && smd->verts) { smd->mesh_verts_num = smd->bind_verts_num; - for (uint i = 0; i < smd->bind_verts_num; i++) { - smd->verts[i].vertex_idx = i; + uint change; + for (uint i = smd->bind_verts_num; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (smd->bind_verts_num - i); + smd->verts[change].vertex_idx = change; } } } @@ -3183,12 +3196,18 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) } LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) { - for (int step = 0; step < 2; step++) { + int change + for (int step = 2; --step) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (2 - step); + CustomDataLayer *actlayer = nullptr; int vact1, vact2; - if (step) { + if (change) { vact1 = CustomData_get_render_layer_index(&me->vdata, CD_PROP_COLOR); vact2 = CustomData_get_render_layer_index(&me->ldata, CD_PROP_BYTE_COLOR); } @@ -3205,7 +3224,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) } if (actlayer) { - if (step) { + if (change) { BKE_id_attributes_default_color_set(&me->id, actlayer->name); } else { @@ -3348,12 +3367,18 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) /* Rebuild active/render color attribute references. */ LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) { - for (int step = 0; step < 2; step++) { + int change; + for (int step = 2; --step) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (2 - step); + CustomDataLayer *actlayer = nullptr; int vact1, vact2; - if (step) { + if (change) { vact1 = CustomData_get_render_layer_index(&me->vdata, CD_PROP_COLOR); vact2 = CustomData_get_render_layer_index(&me->ldata, CD_PROP_BYTE_COLOR); } @@ -3370,7 +3395,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) } if (actlayer) { - if (step) { + if (change) { BKE_id_attributes_default_color_set(&me->id, actlayer->name); } else { @@ -3386,13 +3411,18 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) if (md->type == eModifierType_DataTransfer) { DataTransferModifierData *dtmd = (DataTransferModifierData *)md; - for (int i = 0; i < DT_MULTILAYER_INDEX_MAX; i++) { - if (dtmd->layers_select_src[i] == 0) { - dtmd->layers_select_src[i] = DT_LAYERS_ALL_SRC; + int change; + for (int i = DT_MULTILAYER_INDEX_MAX; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (DT_MULTILAYER_INDEX_MAX - i); + if (dtmd->layers_select_src[change] == 0) { + dtmd->layers_select_src[change] = DT_LAYERS_ALL_SRC; } - if (dtmd->layers_select_dst[i] == 0) { - dtmd->layers_select_dst[i] = DT_LAYERS_NAME_DST; + if (dtmd->layers_select_dst[change] == 0) { + dtmd->layers_select_dst[change] = DT_LAYERS_NAME_DST; } } } @@ -3677,8 +3707,13 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) { int *face_sets = (int *)CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS); if (face_sets) { - for (int i = 0; i < mesh->totpoly; i++) { - face_sets[i] = abs(face_sets[i]); + int change; + for (int i = mesh->totpoly; --i) { + /*optimized loop to use deincrement instead to use less resources + because now it automatically stops when a reaches 0 and it loops + the same number of times*/ + change = (mesh->totpoly - i); + face_sets[change] = abs(face_sets[change]); } } } -- 2.30.2 From 2d8d65520b67b2765df184970ac39c923a24c952 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Thu, 16 Mar 2023 20:27:29 +0100 Subject: [PATCH 11/31] did a loop optimizations to source/blender/blenloader/intern/versioning_cycles.c replace postincrement in a for loop with predecrement --- .../blender/blenloader/intern/versioning_cycles.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c index 67772140466..d4b23637e53 100644 --- a/source/blender/blenloader/intern/versioning_cycles.c +++ b/source/blender/blenloader/intern/versioning_cycles.c @@ -255,12 +255,16 @@ static void vector_curve_node_remap(bNode *node) CurveMapping *mapping = node->storage; mapping->flag &= ~CUMA_DO_CLIP; - for (int curve_index = 0; curve_index < CM_TOT; curve_index++) { - CurveMap *cm = &mapping->cm[curve_index]; + int change1; + for (int curve_index = CM_TOT; --curve_index) { + change = (CM_TOT - curve_index); + CurveMap *cm = &mapping->cm[change]; if (cm->curve) { - for (int i = 0; i < cm->totpoint; i++) { - cm->curve[i].x = (cm->curve[i].x * 2.0f) - 1.0f; - cm->curve[i].y = (cm->curve[i].y - 0.5f) * 2.0f; + int change2; + for (int i = cm->totpoint; --i) { + change2 = (cm->totpoint - i); + cm->curve[change].x = (cm->curve[change].x * 2.0f) - 1.0f; + cm->curve[chnage].y = (cm->curve[change].y - 0.5f) * 2.0f; } } } -- 2.30.2 From e4a2de4a9cc557dbd865b94717e4149b5d964afa Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Fri, 17 Mar 2023 01:46:37 +0100 Subject: [PATCH 12/31] did small loop optimizations to source/blender/blenloader/intern/writefile.cc optimized some while loops by replacing postfix with prefix --- source/blender/blenloader/intern/writefile.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/blenloader/intern/writefile.cc b/source/blender/blenloader/intern/writefile.cc index 299735ccab0..630be91234a 100644 --- a/source/blender/blenloader/intern/writefile.cc +++ b/source/blender/blenloader/intern/writefile.cc @@ -953,7 +953,7 @@ static void write_libraries(WriteData *wd, Main *main) } else { found_one = false; - while (!found_one && tot--) { + while (!found_one && --tot) { for (id = static_cast(lbarray[tot]->first); id; id = static_cast(id->next)) { if (id->us > 0 && ((id->tag & LIB_TAG_EXTERN) || @@ -989,7 +989,7 @@ static void write_libraries(WriteData *wd, Main *main) } /* Write link placeholders for all direct linked IDs. */ - while (a--) { + while (--a) { for (id = static_cast(lbarray[a]->first); id; id = static_cast(id->next)) { if (id->us > 0 && ((id->tag & LIB_TAG_EXTERN) || @@ -1181,7 +1181,7 @@ static bool write_file_handle(Main *mainvar, do { ListBase *lbarray[INDEX_ID_MAX]; int a = set_listbasepointers(bmain, lbarray); - while (a--) { + while (--a) { ID *id = static_cast(lbarray[a]->first); if (id == nullptr || GS(id->name) == ID_LI) { -- 2.30.2 From cddb5d41f7c71debcda6fb896b5d9a65277d3afa Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 3 Apr 2023 06:14:12 +0200 Subject: [PATCH 13/31] fixed some errors source/blender/blenloader/intern/readblenentry.cc --- source/blender/blenloader/intern/readblenentry.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/blenloader/intern/readblenentry.cc b/source/blender/blenloader/intern/readblenentry.cc index e8cd5df334c..cc29eff4a5e 100644 --- a/source/blender/blenloader/intern/readblenentry.cc +++ b/source/blender/blenloader/intern/readblenentry.cc @@ -228,9 +228,9 @@ static BHead *blo_blendhandle_read_preview_rects(FileData *fd, const PreviewImage *preview_from_file) { int change = 0; - for (int preview_index = NUM_ICON_SIZES; --preview_index) { + for (int preview_index = NUM_ICON_SIZES; --preview_index; ) { //changed it to use decrement instead of increment to use less resources - change = (NUM_ICON_SIZES - preview_index) + change = (NUM_ICON_SIZES - preview_index); if (preview_from_file->rect[change] && preview_from_file->w[change] && preview_from_file->h[change]) { bhead = blo_bhead_next(fd, bhead); -- 2.30.2 From 512aa3bced47381ff1c428f088de9c1050c1b720 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 3 Apr 2023 06:17:46 +0200 Subject: [PATCH 14/31] fixed errors in source/blender/blenloader/intern/readfile.cc --- source/blender/blenloader/intern/readfile.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index 38b11e52956..2c24295ea2c 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -5073,7 +5073,7 @@ static void convert_pointer_array_64_to_32(BlendDataReader *reader, /* Match pointer conversion rules from bh4_from_bh8 and cast_pointer. */ if (BLO_read_requires_endian_switch(reader)) { int change = 0; - for (int i = array_size; --i) { + for (int i = array_size; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -5085,7 +5085,7 @@ static void convert_pointer_array_64_to_32(BlendDataReader *reader, } else { int change = 0; - for (int i = array_size; --i) { + for (int i = array_size; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -5102,7 +5102,7 @@ static void convert_pointer_array_32_to_64(BlendDataReader * /*reader*/, { /* Match pointer conversion rules from bh8_from_bh4 and cast_pointer_32_to_64. */ int change = 0; - for (int i = array_size; --i) { + for (int i = array_size; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ -- 2.30.2 From 8a8a8e54f38bbe4954af70ae0a8cb7e67537bd64 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 3 Apr 2023 06:59:43 +0200 Subject: [PATCH 15/31] fixed errors in source/blender/blenloader/intern/versioning_250.c --- .../blender/blenloader/intern/versioning_250.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 74cba2333bb..d06d19a4947 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -826,11 +826,11 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) int change; ob->matbits = MEM_calloc_arrayN(ob->totcol, sizeof(char), "ob->matbits"); - for (a = ob->totcol; --a) { + for (a = ob->totcol; --a; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ - change = (ob->totcol - a) + change = (ob->totcol - a); ob->matbits[change] = (ob->colbits & (1 << change)) != 0; } } @@ -1002,11 +1002,11 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) data = key->refkey->data; tot = MIN2(me->totvert, key->refkey->totelem); MVert *verts = (MVert *)CustomData_get_layer_for_write(&me->vdata, CD_MVERT, me->totvert); - for (a = tot; --a, data += 3) { + for (a = tot; --a, data += 3; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ - change = (tot - a) + change = (tot - a); copy_v3_v3(verts[change].co_legacy, data); } } @@ -1035,7 +1035,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (nu->bezt) { BezTriple *bezt = nu->bezt; - for (a = nu->pntsu; --a, bezt++) { + for (a = nu->pntsu; --a, bezt++; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -1052,7 +1052,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) else if (nu->bp) { BPoint *bp = nu->bp; - for (a = nu->pntsu * nu->pntsv; --a, ++bp) { + for (a = nu->pntsu * nu->pntsv; --a, ++bp; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -1443,11 +1443,11 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) ParticleEditSettings *pset = &sce->toolsettings->particle; int a, change; - for (a = ARRAY_SIZE(pset->brush); --a) { + for (a = ARRAY_SIZE(pset->brush); --a; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ - change = (ARRAY_SIZE(pset->brush) - a) + change = (ARRAY_SIZE(pset->brush) - a); pset->brush[change].strength /= 100.0f; } } @@ -1683,7 +1683,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) /* initialize scene active layer */ for (scene = bmain->scenes.first; scene; scene = scene->id.next) { int i, change; - for (i = 20; --i) { + for (i = 20; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ -- 2.30.2 From aa97a81feacce8987a210c2a74789b12dea2a685 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 3 Apr 2023 07:04:47 +0200 Subject: [PATCH 16/31] fixed errors in source/blender/blenloader/intern/versioning_260.c --- source/blender/blenloader/intern/versioning_260.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index d64ed955737..79c9bdb8fb1 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -356,7 +356,7 @@ static void do_versions_mesh_mloopcol_swap_2_62_1(Mesh *me) int change1; int change2; - for (a = me->ldata.totlayer; --a) { + for (a = me->ldata.totlayer; --a; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -365,7 +365,7 @@ static void do_versions_mesh_mloopcol_swap_2_62_1(Mesh *me) if (layer->type == CD_PROP_BYTE_COLOR) { mloopcol = (MLoopCol *)layer->data; - for (i = me->totloop; --i, ++mloopcol) { + for (i = me->totloop; --i, ++mloopcol; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -462,7 +462,7 @@ static void do_versions_affine_tracker_track(MovieTrackingTrack *track) int i; int change; - for (i = track->markersnr; --i) { + for (i = track->markersnr; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -908,11 +908,11 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) /* convert delta addition into delta scale */ int i; int change; - for (i = 3; --i) { + for (i = 3; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ - change = (3 - i) + change = (3 - i); if ((ob->dsize[change] == 0.0f) || /* simple case, user never touched dsize */ (ob->scale[change] == 0.0f)) /* can't scale the dsize to give a non zero result, * so fallback to 1.0f */ -- 2.30.2 From 62a388b1cd931fc487e251170c6869ad4ca820d0 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 3 Apr 2023 22:33:55 +0200 Subject: [PATCH 17/31] fixed error in source/blender/blenloader/intern/versioning_270.c --- .../blenloader/intern/versioning_270.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 76dbb1f4c70..e7ebbc0fdd1 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -809,12 +809,12 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) ParticleSettings *part; for (part = bmain->particles.first; part; part = part->id.next) { int a; - int change - for (a = MAX_MTEX; --a) { + int change; + for (a = MAX_MTEX; --a; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ - change = (MAX_MTEX - a) + change = (MAX_MTEX - a); MTex *mtex = part->mtex[change]; if (mtex) { mtex->kinkampfac = 1.0f; @@ -1169,12 +1169,12 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 277, 1)) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { ParticleEditSettings *pset = &scene->toolsettings->particle; - for (int a = 0; a < ARRAY_SIZE(pset->brush); a++) { + for (int a = 0; a < ARRAY_SIZE(pset->brush); ++a) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ - if (pset->brush[change].strength > 1.0f) { - pset->brush[change].strength *= 0.01f; + if (pset->brush[a].strength > 1.0f) { + pset->brush[a].strength *= 0.01f; } } } @@ -1383,7 +1383,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) /* set alpha strength to 1 */ int change; - for (int i = gps->totpoints; --i) { + for (int i = gps->totpoints; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -1477,11 +1477,11 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) ToolSettings *ts = scene->toolsettings; ParticleEditSettings *pset = &ts->particle; int change; - for (int a = ARRAY_SIZE(pset->brush); --a) { + for (int a = ARRAY_SIZE(pset->brush); --a; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ - change = (ARRAY_SIZE(pset->brush) - a) + change = (ARRAY_SIZE(pset->brush) - a); if (pset->brush[change].count == 0) { pset->brush[change].count = 10; } @@ -1665,7 +1665,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { ToolSettings *ts = scene->toolsettings; int change; - for (int i = 2; --i) { + for (int i = 2; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ -- 2.30.2 From 0c2748f15bf6ac389d2eb2d41cb549d18d6ac468 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 3 Apr 2023 23:50:30 +0200 Subject: [PATCH 18/31] fixed some errors source/blender/blenloader/intern/versioning_280.c --- .../blender/blenloader/intern/versioning_280.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index b70f90f653c..ec7b7056527 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -424,7 +424,7 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) Collection *collections[20] = {NULL}; int change; - for (int layer = 20; --layer) { + for (int layer = 20; --layer; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -491,7 +491,7 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) /* Set exclusion and overrides. */ int change; - for (int layer = 20; --layer) { + for (int layer = 20; --layer; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -912,7 +912,7 @@ static void do_version_curvemapping_flag_extend_extrapolate(CurveMapping *cumap) #define CUMA_EXTEND_EXTRAPOLATE_OLD 1 int change; - for (int curve_map_index = 4; --curve_map_index) { + for (int curve_map_index = 4; --curve_map_index; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -1214,7 +1214,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) Collection **collection_hidden = NULL; int coll_idx = 0; int change = 0; - for (coll_idx= 20; --coll_idx) { + for (coll_idx= 20; --coll_idx; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -1453,7 +1453,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) if (nu->bezt) { BezTriple *bezt = nu->bezt; - for (int a = nu->pntsu; --a, ++bezt) { + for (int a = nu->pntsu; --a, ++bezt; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -1474,7 +1474,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) else if (nu->bp) { BPoint *bp = nu->bp; - for (int a = nu->pntsu * nu->pntsv; --a, ++bp) { + for (int a = nu->pntsu * nu->pntsv; --a, ++bp; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -2585,7 +2585,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { if (ima->type == IMA_TYPE_R_RESULT) { int change; - for (int i = 8; --i) { + for (int i = 8; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -3530,7 +3530,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!DNA_struct_find(fd->filesdna, "TransformOrientationSlot")) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { int change; - for (int i = ARRAY_SIZE(scene->orientation_slots); --i) { + for (int i = ARRAY_SIZE(scene->orientation_slots); --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -4873,7 +4873,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) srgb_to_linearrgb_v4(gps->vert_color_fill, gps->vert_color_fill); int i; bGPDspoint *pt; - for (i = gps->totpoints, pt = gps->points;--i, ++pt) { + for (i = gps->totpoints, pt = gps->points;--i, ++pt; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ -- 2.30.2 From d49e148dac7f51d23c18bbf529e2b146baff79cf Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 3 Apr 2023 23:55:37 +0200 Subject: [PATCH 19/31] Update 'source/blender/blenloader/intern/versioning_280.c' --- source/blender/blenloader/intern/versioning_280.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index ec7b7056527..1f9f49b5d86 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -5126,4 +5126,4 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) { /* Keep this block, even when empty. */ } -} +} \ No newline at end of file -- 2.30.2 From 7f3078a353b7799d5f3d52b129591b76d1d56f03 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Tue, 4 Apr 2023 01:16:32 +0200 Subject: [PATCH 20/31] fixed some errors source/blender/blenloader/intern/versioning_290.cc --- source/blender/blenloader/intern/versioning_290.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_290.cc b/source/blender/blenloader/intern/versioning_290.cc index e498f08775a..f6910bf3fe6 100644 --- a/source/blender/blenloader/intern/versioning_290.cc +++ b/source/blender/blenloader/intern/versioning_290.cc @@ -123,7 +123,7 @@ static void seq_convert_transform_animation(const Sequence *seq, if (fcu != nullptr && !BKE_fcurve_is_empty(fcu)) { BezTriple *bezt = fcu->bezt; int change; - for (int i = fcu->totvert; --i, ++bezt) { + for (int i = fcu->totvert; --i, ++bezt; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -276,7 +276,7 @@ static void seq_convert_transform_animation_2(const Scene *scene, if (fcu != nullptr && !BKE_fcurve_is_empty(fcu)) { BezTriple *bezt = fcu->bezt; int change; - for (int i = fcu->totvert; --i, ++bezt) { + for (int i = fcu->totvert; --i, ++bezt; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -715,7 +715,7 @@ static void do_versions_point_attributes(CustomData *pdata) }; int change; - for (int i = pdata->totlayer; --i) { + for (int i = pdata->totlayer; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -735,7 +735,8 @@ static void do_versions_point_attributes(CustomData *pdata) static void do_versions_point_attribute_names(CustomData *pdata) { /* Change from capital initial letter to lower case (#82693). */ - for (int i = pdata->totlayer; --i) { + int change; + for (int i = pdata->totlayer; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -757,7 +758,7 @@ static void do_versions_point_attribute_names(CustomData *pdata) static void do_versions_291_fcurve_handles_limit(FCurve *fcu) { uint i = (fcu->totvert - 1); - for (BezTriple *bezt = fcu->bezt; --i, ++bezt) { + for (BezTriple *bezt = fcu->bezt; --i, ++bezt; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -866,7 +867,7 @@ void blo_do_versions_290(FileData *fd, Library * /*lib*/, Main *bmain) { short id_codes[] = {ID_BR, ID_PAL}; int change; - for (int i = ARRAY_SIZE(id_codes); --i) { + for (int i = ARRAY_SIZE(id_codes); --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ -- 2.30.2 From cba1de9e20c4deda4d84aaba54233b7ee5db4df9 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Tue, 4 Apr 2023 03:44:22 +0200 Subject: [PATCH 21/31] Update 'source/blender/blenloader/intern/versioning_300.cc' --- .../blender/blenloader/intern/versioning_300.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index ef1b02068ef..dc651ea0205 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -174,7 +174,7 @@ static void version_idproperty_move_data_float(IDPropertyUIDataFloat *ui_data, MEM_malloc_arrayN(array_len, sizeof(double), __func__)); const float *old_default_array = static_cast(IDP_Array(default_value)); int change; - for (int i = ui_data->default_array_len; --i) { + for (int i = ui_data->default_array_len; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -488,7 +488,7 @@ static bool do_versions_sequencer_color_balance_sop(Sequence *seq, void * /*user if (smd->type == seqModifierType_ColorBalance) { StripColorBalance *cb = &((ColorBalanceModifierData *)smd)->color_balance; cb->method = SEQ_COLOR_BALANCE_METHOD_LIFTGAMMAGAIN; - for (int i = 3; --i) { + for (int i = 3; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -2309,7 +2309,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) smd->mesh_verts_num = smd->bind_verts_num; uint change; - for (uint i = smd->bind_verts_num; --i) { + for (uint i = smd->bind_verts_num; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -3196,8 +3196,8 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) } LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) { - int change - for (int step = 2; --step) { + int change; + for (int step = 2; --step; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -3368,7 +3368,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) /* Rebuild active/render color attribute references. */ LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) { int change; - for (int step = 2; --step) { + for (int step = 2; --step; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -3412,7 +3412,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) DataTransferModifierData *dtmd = (DataTransferModifierData *)md; int change; - for (int i = DT_MULTILAYER_INDEX_MAX; --i) { + for (int i = DT_MULTILAYER_INDEX_MAX; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ @@ -3708,7 +3708,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) int *face_sets = (int *)CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS); if (face_sets) { int change; - for (int i = mesh->totpoly; --i) { + for (int i = mesh->totpoly; --i; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ -- 2.30.2 From c9f565181ffeed5e609f65d202c0d474e5e6f33e Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Tue, 4 Apr 2023 03:50:34 +0200 Subject: [PATCH 22/31] Update 'source/blender/blenloader/intern/versioning_cycles.c' --- source/blender/blenloader/intern/versioning_cycles.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c index d4b23637e53..470a7b0ad09 100644 --- a/source/blender/blenloader/intern/versioning_cycles.c +++ b/source/blender/blenloader/intern/versioning_cycles.c @@ -256,15 +256,15 @@ static void vector_curve_node_remap(bNode *node) mapping->flag &= ~CUMA_DO_CLIP; int change1; - for (int curve_index = CM_TOT; --curve_index) { - change = (CM_TOT - curve_index); - CurveMap *cm = &mapping->cm[change]; + for (int curve_index = CM_TOT; --curve_index; ) { + change1 = (CM_TOT - curve_index); + CurveMap *cm = &mapping->cm[change1]; if (cm->curve) { int change2; - for (int i = cm->totpoint; --i) { + for (int i = cm->totpoint; --i; ) { change2 = (cm->totpoint - i); - cm->curve[change].x = (cm->curve[change].x * 2.0f) - 1.0f; - cm->curve[chnage].y = (cm->curve[change].y - 0.5f) * 2.0f; + cm->curve[change2].x = (cm->curve[change2].x * 2.0f) - 1.0f; + cm->curve[change2].y = (cm->curve[change2].y - 0.5f) * 2.0f; } } } -- 2.30.2 From 63f16631000e049f04bf22df4d1ee9a717a7f882 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Tue, 4 Apr 2023 22:25:10 +0200 Subject: [PATCH 23/31] Update 'source/blender/blenloader/intern/versioning_250.c' --- source/blender/blenloader/intern/versioning_250.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index d06d19a4947..2a22aca7893 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -1017,11 +1017,11 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) data = key->refkey->data; tot = MIN2(lt->pntsu * lt->pntsv * lt->pntsw, key->refkey->totelem); - for (a = tot; --a, data += 3) { + for (a = tot; --a, data += 3; ) { /*optimized loop to use deincrement instead to use less resources because now it automatically stops when a reaches 0 and it loops the same number of times*/ - change = (tot - a) + change = (tot - a); copy_v3_v3(lt->def[change].vec, data); } } -- 2.30.2 From 78c79fdf9c70ab8ac861b1f9d262209f26ebcb58 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Fri, 5 May 2023 01:44:28 +0200 Subject: [PATCH 24/31] improved readability --- source/blender/blenloader/intern/readfile.cc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index 2c24295ea2c..51eb4dfca44 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -2782,7 +2782,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main) } } } - +641cb77f593052607838e282 /* Make sure we have full path in lib->filepath_abs */ BLI_strncpy(lib->filepath_abs, lib->filepath, sizeof(lib->filepath)); BLI_path_normalize(fd->relabase, lib->filepath_abs); @@ -5074,9 +5074,7 @@ static void convert_pointer_array_64_to_32(BlendDataReader *reader, if (BLO_read_requires_endian_switch(reader)) { int change = 0; for (int i = array_size; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (array_size - i); uint64_t ptr = src[change]; BLI_endian_switch_uint64(&ptr); @@ -5086,9 +5084,7 @@ static void convert_pointer_array_64_to_32(BlendDataReader *reader, else { int change = 0; for (int i = array_size; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (array_size - i); dst[change] = uint32_t(src[change] >> 3); } @@ -5103,9 +5099,7 @@ static void convert_pointer_array_32_to_64(BlendDataReader * /*reader*/, /* Match pointer conversion rules from bh8_from_bh4 and cast_pointer_32_to_64. */ int change = 0; for (int i = array_size; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (array_size - i); dst[change] = src[change]; } -- 2.30.2 From a864a6f1073fb28f77da9502a510b5bfecee742f Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Fri, 5 May 2023 02:05:25 +0200 Subject: [PATCH 25/31] improved readability --- .../blenloader/intern/versioning_250.c | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 2a22aca7893..b60665766c5 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -827,9 +827,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) ob->matbits = MEM_calloc_arrayN(ob->totcol, sizeof(char), "ob->matbits"); for (a = ob->totcol; --a; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (ob->totcol - a); ob->matbits[change] = (ob->colbits & (1 << change)) != 0; } @@ -1003,9 +1001,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) tot = MIN2(me->totvert, key->refkey->totelem); MVert *verts = (MVert *)CustomData_get_layer_for_write(&me->vdata, CD_MVERT, me->totvert); for (a = tot; --a, data += 3; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (tot - a); copy_v3_v3(verts[change].co_legacy, data); } @@ -1018,9 +1014,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) tot = MIN2(lt->pntsu * lt->pntsv * lt->pntsw, key->refkey->totelem); for (a = tot; --a, data += 3; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (tot - a); copy_v3_v3(lt->def[change].vec, data); } @@ -1035,10 +1029,8 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (nu->bezt) { BezTriple *bezt = nu->bezt; - for (a = nu->pntsu; --a, bezt++; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + for (a = nu->pntsu; --a, ++bezt; ) { + //changed it to use decrement instead of increment to use less resources copy_v3_v3(bezt->vec[0], data); data += 3; copy_v3_v3(bezt->vec[1], data); @@ -1053,9 +1045,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) BPoint *bp = nu->bp; for (a = nu->pntsu * nu->pntsv; --a, ++bp; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources copy_v3_v3(bp->vec, data); data += 3; bp->tilt = *data; @@ -1444,9 +1434,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) int a, change; for (a = ARRAY_SIZE(pset->brush); --a; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (ARRAY_SIZE(pset->brush) - a); pset->brush[change].strength /= 100.0f; } @@ -1684,9 +1672,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { int i, change; for (i = 20; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (20 - i); if (scene->lay & (1 << change)) { scene->layact = 1 << change; @@ -2262,9 +2248,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) /* only change auto-handles to auto-clamped */ for (bezt = fcu->bezt; i = fcu->totvert; --i, ++bezt) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources if (bezt->h1 == HD_AUTO) { bezt->h1 = HD_AUTO_ANIM; } -- 2.30.2 From 45adf17c390177e39e3ad437e3ae109ea8ce20b5 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Fri, 5 May 2023 04:15:28 +0200 Subject: [PATCH 26/31] improved readability --- .../blender/blenloader/intern/versioning_260.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index 79c9bdb8fb1..9da14dc661b 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -357,18 +357,14 @@ static void do_versions_mesh_mloopcol_swap_2_62_1(Mesh *me) int change2; for (a = me->ldata.totlayer; --a; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change1 = (me->ldata.totlayer - a); layer = &me->ldata.layers[a]; if (layer->type == CD_PROP_BYTE_COLOR) { mloopcol = (MLoopCol *)layer->data; for (i = me->totloop; --i, ++mloopcol; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change2 = (me->totloop - i); SWAP(uchar, mloopcol->r, mloopcol->b); } @@ -463,9 +459,7 @@ static void do_versions_affine_tracker_track(MovieTrackingTrack *track) int change; for (i = track->markersnr; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (track->markersnr - i); MovieTrackingMarker *marker = &track->markers[change]; @@ -909,9 +903,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) int i; int change; for (i = 3; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (3 - i); if ((ob->dsize[change] == 0.0f) || /* simple case, user never touched dsize */ (ob->scale[change] == 0.0f)) /* can't scale the dsize to give a non zero result, -- 2.30.2 From cb6faa3f3c1258d6f304a490e5ff75f39ac859ac Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Sun, 7 May 2023 03:47:45 +0200 Subject: [PATCH 27/31] Improved readability of optimization --- .../blenloader/intern/versioning_270.c | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index e7ebbc0fdd1..e6f17a58feb 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -811,9 +811,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) int a; int change; for (a = MAX_MTEX; --a; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (MAX_MTEX - a); MTex *mtex = part->mtex[change]; if (mtex) { @@ -1170,9 +1168,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { ParticleEditSettings *pset = &scene->toolsettings->particle; for (int a = 0; a < ARRAY_SIZE(pset->brush); ++a) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources if (pset->brush[a].strength > 1.0f) { pset->brush[a].strength *= 0.01f; } @@ -1384,9 +1380,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) /* set alpha strength to 1 */ int change; for (int i = gps->totpoints; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (gps->totpoints - i); gps->points[change].strength = 1.0f; } @@ -1478,9 +1472,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) ParticleEditSettings *pset = &ts->particle; int change; for (int a = ARRAY_SIZE(pset->brush); --a; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (ARRAY_SIZE(pset->brush) - a); if (pset->brush[change].count == 0) { pset->brush[change].count = 10; @@ -1666,9 +1658,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) ToolSettings *ts = scene->toolsettings; int change; for (int i = 2; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (2 - i); VPaint *vp = change ? ts->vpaint : ts->wpaint; if (vp != NULL) { -- 2.30.2 From 3f9984a70d2185d49b6388518540cec28352b717 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Sun, 7 May 2023 05:04:15 +0200 Subject: [PATCH 28/31] Improved readability of optimization --- .../blenloader/intern/versioning_280.c | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 1f9f49b5d86..b24981b515d 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -425,9 +425,7 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) int change; for (int layer = 20; --layer; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (20 - layer); LISTBASE_FOREACH (Base *, base, &scene->base) { if (base->lay & (1 << change)) { @@ -492,9 +490,7 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) /* Set exclusion and overrides. */ int change; for (int layer = 20; --layer; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (20 - layer); Collection *collection = collections[change]; if (collection) { @@ -913,9 +909,7 @@ static void do_version_curvemapping_flag_extend_extrapolate(CurveMapping *cumap) #define CUMA_EXTEND_EXTRAPOLATE_OLD 1 int change; for (int curve_map_index = 4; --curve_map_index; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (4 - curve_map_index); CurveMap *cuma = &cumap->cm[change]; if (cuma->flag & CUMA_EXTEND_EXTRAPOLATE_OLD) { @@ -1215,9 +1209,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) int coll_idx = 0; int change = 0; for (coll_idx= 20; --coll_idx; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (20 - coll_idx); if (ob->lay & (1 << change)) { collection_hidden = &hidden_collection_array[change]; @@ -1454,9 +1446,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) BezTriple *bezt = nu->bezt; for (int a = nu->pntsu; --a, ++bezt; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources if ((old_count -= 3) < 0) { memcpy(newptr, bezt->vec, sizeof(float[3][3])); newptr[3][0] = bezt->tilt; @@ -1475,9 +1465,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) BPoint *bp = nu->bp; for (int a = nu->pntsu * nu->pntsv; --a, ++bp; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources if (--old_count < 0) { copy_v3_v3(newptr[0], bp->vec); newptr[1][0] = bp->tilt; @@ -2586,9 +2574,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (ima->type == IMA_TYPE_R_RESULT) { int change; for (int i = 8; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (8 - i); RenderSlot *slot = MEM_callocN(sizeof(RenderSlot), "Image Render Slot Init"); BLI_snprintf(slot->name, sizeof(slot->name), "Slot %d", change + 1); @@ -3531,9 +3517,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { int change; for (int i = ARRAY_SIZE(scene->orientation_slots); --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (ARRAY_SIZE(scene->orientation_slots) - i); scene->orientation_slots[change].index_custom = -1; } @@ -4874,9 +4858,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) int i; bGPDspoint *pt; for (i = gps->totpoints, pt = gps->points;--i, ++pt; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources srgb_to_linearrgb_v4(pt->vert_color, pt->vert_color); } } -- 2.30.2 From 4bfe1413fae03e5b897cae8dfaef67de612c5f46 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Mon, 8 May 2023 09:08:52 +0200 Subject: [PATCH 29/31] improved readability of optimization --- .../blender/blenloader/intern/versioning_290.cc | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_290.cc b/source/blender/blenloader/intern/versioning_290.cc index f6910bf3fe6..fa821781620 100644 --- a/source/blender/blenloader/intern/versioning_290.cc +++ b/source/blender/blenloader/intern/versioning_290.cc @@ -124,9 +124,7 @@ static void seq_convert_transform_animation(const Sequence *seq, BezTriple *bezt = fcu->bezt; int change; for (int i = fcu->totvert; --i, ++bezt; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources /* Same math as with old_image_center_*, but simplified. */ bezt->vec[0][1] = (image_size - scene_size) / 2 + bezt->vec[0][1]; bezt->vec[1][1] = (image_size - scene_size) / 2 + bezt->vec[1][1]; @@ -277,9 +275,7 @@ static void seq_convert_transform_animation_2(const Scene *scene, BezTriple *bezt = fcu->bezt; int change; for (int i = fcu->totvert; --i, ++bezt; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources /* Same math as with old_image_center_*, but simplified. */ bezt->vec[0][1] *= scale_to_fit_factor; bezt->vec[1][1] *= scale_to_fit_factor; @@ -737,9 +733,7 @@ static void do_versions_point_attribute_names(CustomData *pdata) /* Change from capital initial letter to lower case (#82693). */ int change; for (int i = pdata->totlayer; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (pdata->totlayer - i); CustomDataLayer *layer = &pdata->layers[change]; if (layer->type == CD_PROP_FLOAT3 && STREQ(layer->name, "Position")) { @@ -759,9 +753,7 @@ static void do_versions_291_fcurve_handles_limit(FCurve *fcu) { uint i = (fcu->totvert - 1); for (BezTriple *bezt = fcu->bezt; --i, ++bezt; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources /* Only adjust bezier key-frames. */ if (bezt->ipo != BEZT_IPO_BEZ) { continue; -- 2.30.2 From 2e125e5f45051335e9ce2b89d967598ebc192b66 Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Tue, 9 May 2023 10:19:50 +0200 Subject: [PATCH 30/31] improved readability of optimization --- .../blenloader/intern/versioning_300.cc | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index dc651ea0205..1a61d16bf0f 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -175,9 +175,7 @@ static void version_idproperty_move_data_float(IDPropertyUIDataFloat *ui_data, const float *old_default_array = static_cast(IDP_Array(default_value)); int change; for (int i = ui_data->default_array_len; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (ui_data->default_array_len - i); ui_data->default_array[change] = double(old_default_array[change]); } @@ -489,9 +487,7 @@ static bool do_versions_sequencer_color_balance_sop(Sequence *seq, void * /*user StripColorBalance *cb = &((ColorBalanceModifierData *)smd)->color_balance; cb->method = SEQ_COLOR_BALANCE_METHOD_LIFTGAMMAGAIN; for (int i = 3; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources copy_v3_fl(cb->slope, 1.0f); copy_v3_fl(cb->offset, 1.0f); copy_v3_fl(cb->power, 1.0f); @@ -2310,9 +2306,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) uint change; for (uint i = smd->bind_verts_num; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (smd->bind_verts_num - i); smd->verts[change].vertex_idx = change; } @@ -3198,9 +3192,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) { int change; for (int step = 2; --step; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (2 - step); CustomDataLayer *actlayer = nullptr; @@ -3369,9 +3361,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) { int change; for (int step = 2; --step; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (2 - step); CustomDataLayer *actlayer = nullptr; @@ -3413,9 +3403,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) int change; for (int i = DT_MULTILAYER_INDEX_MAX; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (DT_MULTILAYER_INDEX_MAX - i); if (dtmd->layers_select_src[change] == 0) { dtmd->layers_select_src[change] = DT_LAYERS_ALL_SRC; @@ -3709,9 +3697,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) if (face_sets) { int change; for (int i = mesh->totpoly; --i; ) { - /*optimized loop to use deincrement instead to use less resources - because now it automatically stops when a reaches 0 and it loops - the same number of times*/ + //changed it to use decrement instead of increment to use less resources change = (mesh->totpoly - i); face_sets[change] = abs(face_sets[change]); } -- 2.30.2 From ecc2e37bf8aed3011f7b571dd09a7d2c41dc15fd Mon Sep 17 00:00:00 2001 From: glitchy-virophage Date: Tue, 9 May 2023 10:49:35 +0200 Subject: [PATCH 31/31] improved readability of optimization --- source/blender/blenloader/intern/versioning_cycles.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c index 470a7b0ad09..f224eaf59d3 100644 --- a/source/blender/blenloader/intern/versioning_cycles.c +++ b/source/blender/blenloader/intern/versioning_cycles.c @@ -262,6 +262,7 @@ static void vector_curve_node_remap(bNode *node) if (cm->curve) { int change2; for (int i = cm->totpoint; --i; ) { + //changed it to use decrement instead of increment to use less resources change2 = (cm->totpoint - i); cm->curve[change2].x = (cm->curve[change2].x * 2.0f) - 1.0f; cm->curve[change2].y = (cm->curve[change2].y - 0.5f) * 2.0f; -- 2.30.2