diff options
author | Bastien Montagne <bastien@blender.org> | 2022-08-12 11:39:03 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-08-12 13:37:10 +0300 |
commit | 12b36168957dd27c253251555c29e8523b94fbe8 (patch) | |
tree | 654af023fc4ae7bc3e6472409140e813efdc9800 /source/blender/blenkernel/intern/collection.c | |
parent | 498e26fa0f6486fa2d3bb0029b11eb1dc48a32be (diff) |
IDType `get_owner`: add an optional hint about owner ID.
In some cases, there is a chance code already knows who might be the
owner of the given ID, in which case it can be more efficient to check
it first (especially in cases like embedded node trees or scene
collections, where the only other way is to loop over all possible
owners currently).
Will be used in next commit in some Outliner fix.
Diffstat (limited to 'source/blender/blenkernel/intern/collection.c')
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 09085fa8ffb..4967e3482c6 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -162,7 +162,7 @@ static void collection_foreach_id(ID *id, LibraryForeachIDData *data) } } -static ID *collection_owner_get(Main *bmain, ID *id) +static ID *collection_owner_get(Main *bmain, ID *id, ID *owner_id_hint) { if ((id->flag & LIB_EMBEDDED_DATA) == 0) { return id; @@ -172,6 +172,11 @@ static ID *collection_owner_get(Main *bmain, ID *id) Collection *master_collection = (Collection *)id; BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0); + if (owner_id_hint != NULL && GS(owner_id_hint->name) == ID_SCE && + ((Scene *)owner_id_hint)->master_collection == master_collection) { + return owner_id_hint; + } + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { if (scene->master_collection == master_collection) { return &scene->id; @@ -713,7 +718,8 @@ void BKE_collection_new_name_get(Collection *collection_parent, char *rname) name = BLI_strdup(DATA_("Collection")); } else if (collection_parent->flag & COLLECTION_IS_MASTER) { - name = BLI_sprintfN(DATA_("Collection %d"), BLI_listbase_count(&collection_parent->children) + 1); + name = BLI_sprintfN(DATA_("Collection %d"), + BLI_listbase_count(&collection_parent->children) + 1); } else { const int number = BLI_listbase_count(&collection_parent->children) + 1; |