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
This commit is contained in:
parent
39c341bf4a
commit
609171d8b7
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user