Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Abrahamsson <erik85>2022-09-14 11:52:25 +0300
committerBastien Montagne <bastien@blender.org>2022-09-14 12:00:37 +0300
commit609171d8b70eb9bf169e598fcf2aa88e5e93b818 (patch)
treef29439aec1e1e463166b4fc6520310cb5ae7dc40 /source/blender/blenkernel/intern/material.c
parent39c341bf4ab9582edc26227447634cae2004baa6 (diff)
Optimization: Exit early when resizing material slots.
When assigning a huge number of materials, like when importing thousands of objects, the function `BKE_objects_materials_test_all` uses quite a lot of resources because of the way it loops through all objects to resize the mat-array. By counting the amount of processed objects and comparing to the number of users of the obdata ID, we can exit early and avoid looping through all objects every time. Reviewed By: mont29 Differential Revision: https://developer.blender.org/D15740
Diffstat (limited to 'source/blender/blenkernel/intern/material.c')
-rw-r--r--source/blender/blenkernel/intern/material.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 59a51436b7b..3ea6dd3d735 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -900,9 +900,15 @@ void BKE_objects_materials_test_all(Main *bmain, ID *id)
}
BKE_main_lock(bmain);
+ int processed_objects = 0;
for (ob = bmain->objects.first; ob; ob = ob->id.next) {
if (ob->data == id) {
BKE_object_material_resize(bmain, ob, *totcol, false);
+ processed_objects++;
+ BLI_assert(processed_objects <= id->us && processed_objects > 0);
+ if (processed_objects == id->us) {
+ break;
+ }
}
}
BKE_main_unlock(bmain);