1
1

Improve performance.

This commit is contained in:
2022-10-14 21:26:14 +02:00
parent 61e7026e27
commit 8aa3b1c2be
2 changed files with 20 additions and 9 deletions

View File

@@ -1095,16 +1095,26 @@ static bool collection_object_add(Main *bmain,
}
}
if (collection_objects == NULL) {
collection_objects = BLI_gset_ptr_new(__func__);
LISTBASE_FOREACH (CollectionObject *, collection_object, &collection->gobject) {
BLI_gset_insert(collection_objects, collection_object->ob);
if (objects_len <= 10) {
/*
* Building a GSet adds overhead. When objects_len is small BLI_findptr is faster.
*/
if (BLI_findptr(&collection->gobject, ob, offsetof(CollectionObject, ob))) {
continue;
}
}
if (!BLI_gset_add(collection_objects, ob)) {
result = false;
continue;
else {
if (collection_objects == NULL) {
int gobject_len = BLI_listbase_count(&collection->gobject);
collection_objects = BLI_gset_ptr_new_ex(__func__, gobject_len + objects_len);
LISTBASE_FOREACH (CollectionObject *, collection_object, &collection->gobject) {
BLI_gset_insert(collection_objects, collection_object->ob);
}
}
if (!BLI_gset_add(collection_objects, ob)) {
result = false;
continue;
}
}
CollectionObject *cob = MEM_callocN(sizeof(CollectionObject), __func__);

View File

@@ -479,8 +479,9 @@ static PyObject *bpy_link_multiple(PyObject *self, PyObject *args, PyObject *kwd
objs[i] = obj;
}
Py_DECREF(objects_fast);
BKE_collection_object_add_multiple(bmain, collection, objs, objects_len);
for (int j = 0; j < objects_len; j++) {
BKE_collection_object_add(bmain, collection, objs[j]);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, &objs[j]->id);
}
MEM_freeN(objs);