diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-02-27 03:59:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-02-27 03:59:08 +0400 |
commit | c62a4629979c1ce95f5d001870583d5463062cf4 (patch) | |
tree | 2bc07106d682d1c193d71bc22614f771c3060f23 /source/blender | |
parent | 3ba37b65a32541ac594183d45c0939ee95bb098d (diff) |
use LIKELY/UNLIKELY macros for operations that run a lot.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_iterators_inline.c | 32 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.c | 16 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.h | 6 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.h | 12 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_anim.c | 1 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils.c | 12 |
6 files changed, 49 insertions, 30 deletions
diff --git a/source/blender/bmesh/intern/bmesh_iterators_inline.c b/source/blender/bmesh/intern/bmesh_iterators_inline.c index e4ad53ee46d..37105ea95d5 100644 --- a/source/blender/bmesh/intern/bmesh_iterators_inline.c +++ b/source/blender/bmesh/intern/bmesh_iterators_inline.c @@ -76,80 +76,90 @@ BM_INLINE int BM_iter_init(BMIter *iter, BMesh *bm, const char itype, void *data iter->step = bmiter__face_of_mesh_step; break; case BM_EDGES_OF_VERT: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__edge_of_vert_begin; iter->step = bmiter__edge_of_vert_step; iter->vdata = data; break; case BM_FACES_OF_VERT: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__face_of_vert_begin; iter->step = bmiter__face_of_vert_step; iter->vdata = data; break; case BM_LOOPS_OF_VERT: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__loop_of_vert_begin; iter->step = bmiter__loop_of_vert_step; iter->vdata = data; break; case BM_VERTS_OF_EDGE: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__vert_of_edge_begin; iter->step = bmiter__vert_of_edge_step; iter->edata = data; break; case BM_FACES_OF_EDGE: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__face_of_edge_begin; iter->step = bmiter__face_of_edge_step; iter->edata = data; break; case BM_VERTS_OF_FACE: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__vert_of_face_begin; iter->step = bmiter__vert_of_face_step; iter->pdata = data; break; case BM_EDGES_OF_FACE: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__edge_of_face_begin; iter->step = bmiter__edge_of_face_step; iter->pdata = data; break; case BM_LOOPS_OF_FACE: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__loop_of_face_begin; iter->step = bmiter__loop_of_face_step; iter->pdata = data; break; case BM_LOOPS_OF_LOOP: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__loops_of_loop_begin; iter->step = bmiter__loops_of_loop_step; iter->ldata = data; break; case BM_LOOPS_OF_EDGE: - if (!data) + if (UNLIKELY(!data)) { return FALSE; + } iter->begin = bmiter__loops_of_edge_begin; iter->step = bmiter__loops_of_edge_step; @@ -174,7 +184,7 @@ BM_INLINE int BM_iter_init(BMIter *iter, BMesh *bm, const char itype, void *data */ BM_INLINE void *BM_iter_new(BMIter *iter, BMesh *bm, const char itype, void *data) { - if (BM_iter_init(iter, bm, itype, data)) { + if (LIKELY(BM_iter_init(iter, bm, itype, data))) { return BM_iter_step(iter); } else { diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 14acc305e64..1f65ef2ce11 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -244,7 +244,7 @@ PyDoc_STRVAR(bpy_bm_is_valid_doc, ); static PyObject *bpy_bm_is_valid_get(BPy_BMGeneric *self) { - return PyBool_FromLong(self->bm != NULL); + return PyBool_FromLong(BPY_BM_IS_VALID(self)); } @@ -2453,13 +2453,15 @@ PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele) int bpy_bm_generic_valid_check(BPy_BMGeneric *self) { - if (self->bm) { + if (LIKELY(self->bm)) { return 0; } - PyErr_Format(PyExc_ReferenceError, - "BMesh data of type %.200s has been removed", - Py_TYPE(self)->tp_name); - return -1; + else { + PyErr_Format(PyExc_ReferenceError, + "BMesh data of type %.200s has been removed", + Py_TYPE(self)->tp_name); + return -1; + } } void bpy_bm_generic_invalidate(BPy_BMGeneric *self) @@ -2513,7 +2515,7 @@ void *BPy_BMElem_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ error_prefix, type->tp_name, Py_TYPE(item)->tp_name); goto err_cleanup; } - else if (item->bm == NULL) { + else if (!BPY_BM_IS_VALID(item)) { PyErr_Format(PyExc_TypeError, "%s: %d %s has been removed", error_prefix, i, type->tp_name); diff --git a/source/blender/python/bmesh/bmesh_py_types.h b/source/blender/python/bmesh/bmesh_py_types.h index 6d4444b4662..d7deb41c4e3 100644 --- a/source/blender/python/bmesh/bmesh_py_types.h +++ b/source/blender/python/bmesh/bmesh_py_types.h @@ -137,8 +137,10 @@ void *BPy_BMElem_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ const char do_unique_check, const char do_bm_check, const char *error_prefix); -#define BPY_BM_CHECK_OBJ(obj) if (bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1) { return NULL; } (void)NULL -#define BPY_BM_CHECK_INT(obj) if (bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1) { return -1; } (void)NULL +#define BPY_BM_CHECK_OBJ(obj) if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return NULL; } (void)0 +#define BPY_BM_CHECK_INT(obj) if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return -1; } (void)0 + +#define BPY_BM_IS_VALID(obj) (LIKELY((obj)->bm != NULL)) #define BM_ITER_BPY_BM_SEQ(ele, iter, bpy_bmelemseq) \ BM_ITER(ele, iter, (bpy_bmelemseq)->bm, (bpy_bmelemseq)->itype, \ diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index c9ff034716d..113367788b6 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -83,14 +83,14 @@ extern PyTypeObject pyrna_func_Type; #define BPy_PropertyRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_prop_Type)) #define BPy_PropertyRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_prop_Type) -#define PYRNA_STRUCT_CHECK_OBJ(obj) if(pyrna_struct_validity_check(obj) == -1) { return NULL; } -#define PYRNA_STRUCT_CHECK_INT(obj) if(pyrna_struct_validity_check(obj) == -1) { return -1; } +#define PYRNA_STRUCT_CHECK_OBJ(obj) if (UNLIKELY(pyrna_struct_validity_check(obj) == -1)) { return NULL; } (void)0 +#define PYRNA_STRUCT_CHECK_INT(obj) if (UNLIKELY(pyrna_struct_validity_check(obj) == -1)) { return -1; } (void)0 -#define PYRNA_PROP_CHECK_OBJ(obj) if(pyrna_prop_validity_check(obj) == -1) { return NULL; } -#define PYRNA_PROP_CHECK_INT(obj) if(pyrna_prop_validity_check(obj) == -1) { return -1; } +#define PYRNA_PROP_CHECK_OBJ(obj) if (UNLIKELY(pyrna_prop_validity_check(obj) == -1)) { return NULL; } (void)0 +#define PYRNA_PROP_CHECK_INT(obj) if (UNLIKELY(pyrna_prop_validity_check(obj) == -1)) { return -1; } (void)0 -#define PYRNA_STRUCT_IS_VALID(pysrna) (((BPy_StructRNA *)(pysrna))->ptr.type != NULL) -#define PYRNA_PROP_IS_VALID(pysrna) (((BPy_PropertyRNA *)(pysrna))->ptr.type != NULL) +#define PYRNA_STRUCT_IS_VALID(pysrna) (LIKELY(((BPy_StructRNA *)(pysrna))->ptr.type != NULL)) +#define PYRNA_PROP_IS_VALID(pysrna) (LIKELY(((BPy_PropertyRNA *)(pysrna))->ptr.type != NULL)) /* 'in_weakreflist' MUST be aligned */ diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c index 2371ca7dc50..4b4d0ff3535 100644 --- a/source/blender/python/intern/bpy_rna_anim.c +++ b/source/blender/python/intern/bpy_rna_anim.c @@ -31,6 +31,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" #include "BLI_string.h" #include "DNA_scene_types.h" diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c index a9a9ba8643c..e6be81f88a3 100644 --- a/source/blender/python/mathutils/mathutils.c +++ b/source/blender/python/mathutils/mathutils.c @@ -304,8 +304,9 @@ int Mathutils_RegisterCallback(Mathutils_Callback *cb) int _BaseMathObject_ReadCallback(BaseMathObject *self) { Mathutils_Callback *cb = mathutils_callbacks[self->cb_type]; - if (cb->get(self, self->cb_subtype) != -1) + if (LIKELY(cb->get(self, self->cb_subtype) != -1)) { return 0; + } if (!PyErr_Occurred()) { PyErr_Format(PyExc_RuntimeError, @@ -318,8 +319,9 @@ int _BaseMathObject_ReadCallback(BaseMathObject *self) int _BaseMathObject_WriteCallback(BaseMathObject *self) { Mathutils_Callback *cb = mathutils_callbacks[self->cb_type]; - if (cb->set(self, self->cb_subtype) != -1) + if (LIKELY(cb->set(self, self->cb_subtype) != -1)) { return 0; + } if (!PyErr_Occurred()) { PyErr_Format(PyExc_RuntimeError, @@ -332,8 +334,9 @@ int _BaseMathObject_WriteCallback(BaseMathObject *self) int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index) { Mathutils_Callback *cb = mathutils_callbacks[self->cb_type]; - if (cb->get_index(self, self->cb_subtype, index) != -1) + if (LIKELY(cb->get_index(self, self->cb_subtype, index) != -1)) { return 0; + } if (!PyErr_Occurred()) { PyErr_Format(PyExc_RuntimeError, @@ -346,8 +349,9 @@ int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index) int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index) { Mathutils_Callback *cb = mathutils_callbacks[self->cb_type]; - if (cb->set_index(self, self->cb_subtype, index) != -1) + if (LIKELY(cb->set_index(self, self->cb_subtype, index) != -1)) { return 0; + } if (!PyErr_Occurred()) { PyErr_Format(PyExc_RuntimeError, |