diff options
author | Bastien Montagne <b.mont29@gmail.com> | 2020-03-17 13:13:14 +0300 |
---|---|---|
committer | Bastien Montagne <b.mont29@gmail.com> | 2020-03-17 13:13:14 +0300 |
commit | 90ce708ef0b086c4cd148996cb039cd7ece21457 (patch) | |
tree | 5b1b5c3d0110c339e90a6fefa4d2a04d518fca76 /source/blender/blenkernel/intern/lib_id.c | |
parent | b87997f59b41471f7f79d9071846b2145589d9b2 (diff) |
BKE_lib_id: Add helper to swap full ID content and use proper naming.
Preliminary work for undo-speedup.
Part of T60695/D6580.
Diffstat (limited to 'source/blender/blenkernel/intern/lib_id.c')
-rw-r--r-- | source/blender/blenkernel/intern/lib_id.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 27d4b8dd047..1ae53f5a85d 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -597,7 +597,7 @@ bool BKE_id_copy(Main *bmain, const ID *id, ID **newid) * Does a mere memory swap over the whole IDs data (including type-specific memory). * \note Most internal ID data itself is not swapped (only IDProperties are). */ -void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b) +static void id_swap(Main *bmain, ID *id_a, ID *id_b, const bool do_full_id) { BLI_assert(GS(id_a->name) == GS(id_b->name)); @@ -651,17 +651,45 @@ void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b) #undef CASE_SWAP - /* Restore original ID's internal data. */ - *id_a = id_a_back; - *id_b = id_b_back; + if (!do_full_id) { + /* Restore original ID's internal data. */ + *id_a = id_a_back; + *id_b = id_b_back; - /* Exception: IDProperties. */ - id_a->properties = id_b_back.properties; - id_b->properties = id_a_back.properties; + /* Exception: IDProperties. */ + id_a->properties = id_b_back.properties; + id_b->properties = id_a_back.properties; + } - /* Swap will have broken internal references to itself, restore them. */ - BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, ID_REMAP_SKIP_NEVER_NULL_USAGE); - BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, ID_REMAP_SKIP_NEVER_NULL_USAGE); + if (bmain != NULL) { + /* Swap will have broken internal references to itself, restore them. */ + BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, ID_REMAP_SKIP_NEVER_NULL_USAGE); + BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, ID_REMAP_SKIP_NEVER_NULL_USAGE); + } +} + +/** + * Does a mere memory swap over the whole IDs data (including type-specific memory). + * \note Most internal ID data itself is not swapped (only IDProperties are). + * + * \param bmain May be NULL, in which case there will be no remapping of internal pointers to + * itself. + */ +void BKE_lib_id_swap(Main *bmain, ID *id_a, ID *id_b) +{ + id_swap(bmain, id_a, id_b, false); +} + +/** + * Does a mere memory swap over the whole IDs data (including type-specific memory). + * \note All internal ID data itself is also swapped. + * + * \param bmain May be NULL, in which case there will be no remapping of internal pointers to + * itself. + */ +void BKE_lib_id_swap_full(Main *bmain, ID *id_a, ID *id_b) +{ + id_swap(bmain, id_a, id_b, true); } /** Does *not* set ID->newid pointer. */ |