use LIKELY/UNLIKELY macros for operations that run a lot.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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, \
|
||||
|
@@ -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 */
|
||||
|
||||
|
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_string.h"
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user