diff options
author | Bastien Montagne <b.mont29@gmail.com> | 2020-03-20 13:55:34 +0300 |
---|---|---|
committer | Bastien Montagne <b.mont29@gmail.com> | 2020-03-20 13:55:34 +0300 |
commit | d931aacef6f34578a9760a96811b916ea85c5d0f (patch) | |
tree | 9015eea0e3615f50a7e0e048614b09d9ea2b1246 /source | |
parent | 6cbf342cbb25bcdbc7f6eebbea41dd5ef25a40c1 (diff) |
Cleanup: Use IDTypeInfo data for `id_swap` functions.
Part of T74960.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/lib_id.c | 59 |
1 files changed, 10 insertions, 49 deletions
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index c912ea2477c..a524db3c909 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -71,6 +71,7 @@ #include "BLI_utildefines.h" +#include "BLI_alloca.h" #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_linklist.h" @@ -624,58 +625,18 @@ 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)); + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id_a); + BLI_assert(id_type != NULL); + const size_t id_struct_size = id_type->struct_size; + const ID id_a_back = *id_a; const ID id_b_back = *id_b; -#define CASE_SWAP(_gs, _type) \ - case _gs: \ - SWAP(_type, *(_type *)id_a, *(_type *)id_b); \ - break - - switch ((ID_Type)GS(id_a->name)) { - CASE_SWAP(ID_SCE, Scene); - CASE_SWAP(ID_LI, Library); - CASE_SWAP(ID_OB, Object); - CASE_SWAP(ID_ME, Mesh); - CASE_SWAP(ID_CU, Curve); - CASE_SWAP(ID_MB, MetaBall); - CASE_SWAP(ID_MA, Material); - CASE_SWAP(ID_TE, Tex); - CASE_SWAP(ID_IM, Image); - CASE_SWAP(ID_LT, Lattice); - CASE_SWAP(ID_LA, Light); - CASE_SWAP(ID_LP, LightProbe); - CASE_SWAP(ID_CA, Camera); - CASE_SWAP(ID_KE, Key); - CASE_SWAP(ID_WO, World); - CASE_SWAP(ID_SCR, bScreen); - CASE_SWAP(ID_VF, VFont); - CASE_SWAP(ID_TXT, Text); - CASE_SWAP(ID_SPK, Speaker); - CASE_SWAP(ID_SO, bSound); - CASE_SWAP(ID_GR, Collection); - CASE_SWAP(ID_AR, bArmature); - CASE_SWAP(ID_AC, bAction); - CASE_SWAP(ID_NT, bNodeTree); - CASE_SWAP(ID_BR, Brush); - CASE_SWAP(ID_PA, ParticleSettings); - CASE_SWAP(ID_WM, wmWindowManager); - CASE_SWAP(ID_WS, WorkSpace); - CASE_SWAP(ID_GD, bGPdata); - CASE_SWAP(ID_MC, MovieClip); - CASE_SWAP(ID_MSK, Mask); - CASE_SWAP(ID_LS, FreestyleLineStyle); - CASE_SWAP(ID_PAL, Palette); - CASE_SWAP(ID_PC, PaintCurve); - CASE_SWAP(ID_CF, CacheFile); - CASE_SWAP(ID_HA, Hair); - CASE_SWAP(ID_PT, PointCloud); - CASE_SWAP(ID_VO, Volume); - case ID_IP: - break; /* Deprecated. */ - } - -#undef CASE_SWAP + char *id_swap_buff = alloca(id_struct_size); + + memcpy(id_swap_buff, id_a, id_struct_size); + memcpy(id_a, id_b, id_struct_size); + memcpy(id_b, id_swap_buff, id_struct_size); if (!do_full_id) { /* Restore original ID's internal data. */ |