eina_matrix: optimize multiply and inverse calls by actually using the shortcut

We had this nice shortcuts for multiply and inverse with the identity matrix.
Pity we never used it! The EINA_MATRIX_TYPE_IDENTITY is coming from an enum
without and direct assignments to its internals. Being the first item in the
enum it is most likely will be 0 which makes the whole bitwise AND zero and thus
the optimized path will never get called. If our compiler now decides hew wants
to handle enums differently and does not assign the 0 to the first item this
bitwise operation will be even more screwed. What we really want is to check is
if the type we get for the matrix matches EINA_MATRIX_TYPE_IDENTITY. So better
do this. Made me look into matrix multply and inverse. Fun!

Thanks to smatch for poiting this out.
This commit is contained in:
Stefan Schmidt 2015-11-27 00:13:04 +01:00
parent 7b86b1c374
commit a486671bce
1 changed files with 7 additions and 7 deletions

View File

@ -991,13 +991,13 @@ EAPI void
eina_matrix4_multiply(Eina_Matrix4 *out, const Eina_Matrix4 *mat_a,
const Eina_Matrix4 *mat_b)
{
if (eina_matrix4_type_get(mat_a) & EINA_MATRIX_TYPE_IDENTITY)
if (eina_matrix4_type_get(mat_a) == EINA_MATRIX_TYPE_IDENTITY)
{
eina_matrix4_copy(out, mat_b);
return;
}
if (eina_matrix4_type_get(mat_b) & EINA_MATRIX_TYPE_IDENTITY)
if (eina_matrix4_type_get(mat_b) == EINA_MATRIX_TYPE_IDENTITY)
{
eina_matrix4_copy(out, mat_a);
return;
@ -1085,13 +1085,13 @@ eina_matrix3_copy(Eina_Matrix3 *dst, const Eina_Matrix3 *src)
EAPI void
eina_matrix3_multiply(Eina_Matrix3 *out, const Eina_Matrix3 *mat_a, const Eina_Matrix3 *mat_b)
{
if (eina_matrix3_type_get(mat_a) & EINA_MATRIX_TYPE_IDENTITY)
if (eina_matrix3_type_get(mat_a) == EINA_MATRIX_TYPE_IDENTITY)
{
eina_matrix3_copy(out, mat_b);
return;
}
if (eina_matrix3_type_get(mat_b) & EINA_MATRIX_TYPE_IDENTITY)
if (eina_matrix3_type_get(mat_b) == EINA_MATRIX_TYPE_IDENTITY)
{
eina_matrix3_copy(out, mat_a);
return;
@ -1206,7 +1206,7 @@ eina_matrix2_inverse(Eina_Matrix2 *out, const Eina_Matrix2 *mat)
{
double det;
if (eina_matrix2_type_get(mat) & EINA_MATRIX_TYPE_IDENTITY)
if (eina_matrix2_type_get(mat) == EINA_MATRIX_TYPE_IDENTITY)
{
eina_matrix2_copy(out, mat);
return;
@ -1250,13 +1250,13 @@ eina_matrix2_copy(Eina_Matrix2 *dst, const Eina_Matrix2 *src)
EAPI void
eina_matrix2_multiply(Eina_Matrix2 *out, const Eina_Matrix2 *mat_a, const Eina_Matrix2 *mat_b)
{
if (eina_matrix2_type_get(mat_a) & EINA_MATRIX_TYPE_IDENTITY)
if (eina_matrix2_type_get(mat_a) == EINA_MATRIX_TYPE_IDENTITY)
{
eina_matrix2_copy(out, mat_b);
return;
}
if (eina_matrix2_type_get(mat_b) & EINA_MATRIX_TYPE_IDENTITY)
if (eina_matrix2_type_get(mat_b) == EINA_MATRIX_TYPE_IDENTITY)
{
eina_matrix2_copy(out, mat_a);
return;