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:
authorJeroen Bakker <j.bakker@atmind.nl>2022-10-14 22:26:14 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2022-10-14 22:26:14 +0300
commit8aa3b1c2be375801c0a4fdc93c61ee24862883af (patch)
treef84dd885a9c7eb8cf1c834f3710fb85fce511961
parent61e7026e272b5627df97d17ba2941336a4b9b241 (diff)
-rw-r--r--source/blender/blenkernel/intern/collection.c26
-rw-r--r--source/blender/python/intern/bpy_rna_id_collection.c3
2 files changed, 20 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 42b709104f3..faec986dded 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -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__);
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c
index 10b7ba50988..bd2058394d8 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -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);