[Bf-blender-cvs] [d931aacef6f] master: Cleanup: Use IDTypeInfo data for `id_swap` functions.
Bastien Montagne
noreply at git.blender.org
Fri Mar 20 11:58:01 CET 2020
Commit: d931aacef6f34578a9760a96811b916ea85c5d0f
Author: Bastien Montagne
Date: Fri Mar 20 11:55:34 2020 +0100
Branches: master
https://developer.blender.org/rBd931aacef6f34578a9760a96811b916ea85c5d0f
Cleanup: Use IDTypeInfo data for `id_swap` functions.
Part of T74960.
===================================================================
M source/blender/blenkernel/intern/lib_id.c
===================================================================
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. */
More information about the Bf-blender-cvs
mailing list