make SWAP macros typesafe using CHECK_TYPE macro.
Its unlikely you want to do short -> int, int -> float etc, conversion during swapping (if its needed we could have a non type checking macro). Double that the optimized assembler outbut using SWAP() remains unchanged from before. This exposed quite a few places where redundant type conversion was going on. Also remove curve.c's swapdata() and replace its use with swap_v3_v3()
This commit is contained in:
@@ -3047,29 +3047,6 @@ void BKE_nurbList_handles_set(ListBase *editnurb, short code)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void swapdata(void *adr1, void *adr2, int len)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (len <= 0) return;
|
|
||||||
|
|
||||||
if (len < 65) {
|
|
||||||
char adr[64];
|
|
||||||
|
|
||||||
memcpy(adr, adr1, len);
|
|
||||||
memcpy(adr1, adr2, len);
|
|
||||||
memcpy(adr2, adr, len);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
char *adr;
|
|
||||||
|
|
||||||
adr = (char *)MEM_mallocN(len, "curve swap");
|
|
||||||
memcpy(adr, adr1, len);
|
|
||||||
memcpy(adr1, adr2, len);
|
|
||||||
memcpy(adr2, adr, len);
|
|
||||||
MEM_freeN(adr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BKE_nurb_direction_switch(Nurb *nu)
|
void BKE_nurb_direction_switch(Nurb *nu)
|
||||||
{
|
{
|
||||||
BezTriple *bezt1, *bezt2;
|
BezTriple *bezt1, *bezt2;
|
||||||
@@ -3077,7 +3054,9 @@ void BKE_nurb_direction_switch(Nurb *nu)
|
|||||||
float *fp1, *fp2, *tempf;
|
float *fp1, *fp2, *tempf;
|
||||||
int a, b;
|
int a, b;
|
||||||
|
|
||||||
if (nu->pntsu == 1 && nu->pntsv == 1) return;
|
if (nu->pntsu == 1 && nu->pntsv == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (nu->type == CU_BEZIER) {
|
if (nu->type == CU_BEZIER) {
|
||||||
a = nu->pntsu;
|
a = nu->pntsu;
|
||||||
@@ -3086,12 +3065,15 @@ void BKE_nurb_direction_switch(Nurb *nu)
|
|||||||
if (a & 1) a += 1; /* if odd, also swap middle content */
|
if (a & 1) a += 1; /* if odd, also swap middle content */
|
||||||
a /= 2;
|
a /= 2;
|
||||||
while (a > 0) {
|
while (a > 0) {
|
||||||
if (bezt1 != bezt2)
|
if (bezt1 != bezt2) {
|
||||||
SWAP(BezTriple, *bezt1, *bezt2);
|
SWAP(BezTriple, *bezt1, *bezt2);
|
||||||
|
}
|
||||||
|
|
||||||
swapdata(bezt1->vec[0], bezt1->vec[2], 12);
|
swap_v3_v3(bezt1->vec[0], bezt1->vec[2]);
|
||||||
if (bezt1 != bezt2)
|
|
||||||
swapdata(bezt2->vec[0], bezt2->vec[2], 12);
|
if (bezt1 != bezt2) {
|
||||||
|
swap_v3_v3(bezt2->vec[0], bezt2->vec[2]);
|
||||||
|
}
|
||||||
|
|
||||||
SWAP(char, bezt1->h1, bezt1->h2);
|
SWAP(char, bezt1->h1, bezt1->h2);
|
||||||
SWAP(char, bezt1->f1, bezt1->f3);
|
SWAP(char, bezt1->f1, bezt1->f3);
|
||||||
|
@@ -137,8 +137,30 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Causes warning:
|
||||||
|
* incompatible types when assigning to type 'Foo' from type 'Bar'
|
||||||
|
* ... the compiler optimizes away the temp var */
|
||||||
|
#ifndef CHECK_TYPE
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define CHECK_TYPE(var, type) { \
|
||||||
|
__typeof(var) *__tmp; \
|
||||||
|
__tmp = (type *)NULL; \
|
||||||
|
(void)__tmp; \
|
||||||
|
} (void)0
|
||||||
|
#else
|
||||||
|
#define CHECK_TYPE(var, type)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef SWAP
|
#ifndef SWAP
|
||||||
# define SWAP(type, a, b) { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } (void)0
|
# define SWAP(type, a, b) { \
|
||||||
|
type sw_ap; \
|
||||||
|
CHECK_TYPE(a, type); \
|
||||||
|
CHECK_TYPE(b, type); \
|
||||||
|
sw_ap = (a); \
|
||||||
|
(a) = (b); \
|
||||||
|
(b) = sw_ap; \
|
||||||
|
} (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
|
@@ -113,8 +113,30 @@
|
|||||||
|
|
||||||
/* some math and copy defines */
|
/* some math and copy defines */
|
||||||
|
|
||||||
|
/* Causes warning:
|
||||||
|
* incompatible types when assigning to type 'Foo' from type 'Bar'
|
||||||
|
* ... the compiler optimizes away the temp var */
|
||||||
|
#ifndef CHECK_TYPE
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define CHECK_TYPE(var, type) { \
|
||||||
|
__typeof(var) *__tmp; \
|
||||||
|
__tmp = (type *)NULL; \
|
||||||
|
(void)__tmp; \
|
||||||
|
} (void)0
|
||||||
|
#else
|
||||||
|
#define CHECK_TYPE(var, type)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef SWAP
|
#ifndef SWAP
|
||||||
# define SWAP(type, a, b) { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } (void)0
|
# define SWAP(type, a, b) { \
|
||||||
|
type sw_ap; \
|
||||||
|
CHECK_TYPE(a, type); \
|
||||||
|
CHECK_TYPE(b, type); \
|
||||||
|
sw_ap = (a); \
|
||||||
|
(a) = (b); \
|
||||||
|
(b) = sw_ap; \
|
||||||
|
} (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ABS(a) ( (a) < 0 ? (-(a)) : (a) )
|
#define ABS(a) ( (a) < 0 ? (-(a)) : (a) )
|
||||||
|
@@ -313,7 +313,7 @@ static void rna_Object_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
|
|||||||
if (!base)
|
if (!base)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SWAP(int, base->lay, ob->lay);
|
SWAP(unsigned int, base->lay, ob->lay);
|
||||||
|
|
||||||
rna_Object_layer_update__internal(bmain, scene, base, ob);
|
rna_Object_layer_update__internal(bmain, scene, base, ob);
|
||||||
ob->lay = base->lay;
|
ob->lay = base->lay;
|
||||||
|
Reference in New Issue
Block a user