Optimize PySequence_Fast usage
Access arrays directly, avoiding type-check every time.
This commit is contained in:
@@ -742,9 +742,11 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
|
||||
}
|
||||
else {
|
||||
int len = PySequence_Fast_GET_SIZE(seq_fast);
|
||||
PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
PyObject *list_item = PySequence_Fast_GET_ITEM(seq_fast, i);
|
||||
PyObject *list_item = seq_fast_items[i];
|
||||
|
||||
if (BPy_StructRNA_Check(list_item)) {
|
||||
#if 0
|
||||
|
||||
@@ -1319,6 +1319,7 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
|
||||
EnumPropertyItem *items;
|
||||
PyObject *item;
|
||||
const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast);
|
||||
PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
|
||||
Py_ssize_t totbuf = 0;
|
||||
int i;
|
||||
short def_used = 0;
|
||||
@@ -1366,7 +1367,7 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
|
||||
Py_ssize_t name_str_size;
|
||||
Py_ssize_t desc_str_size;
|
||||
|
||||
item = PySequence_Fast_GET_ITEM(seq_fast, i);
|
||||
item = seq_fast_items[i];
|
||||
|
||||
if ((PyTuple_CheckExact(item)) &&
|
||||
(item_size = PyTuple_GET_SIZE(item)) &&
|
||||
|
||||
@@ -2637,6 +2637,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop,
|
||||
int start, int stop, int length, PyObject *value_orig)
|
||||
{
|
||||
PyObject *value;
|
||||
PyObject **value_items;
|
||||
int count;
|
||||
void *values_alloc = NULL;
|
||||
int ret = 0;
|
||||
@@ -2658,6 +2659,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop,
|
||||
return -1;
|
||||
}
|
||||
|
||||
value_items = PySequence_Fast_ITEMS(value);
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_FLOAT:
|
||||
{
|
||||
@@ -2673,7 +2675,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop,
|
||||
RNA_property_float_get_array(ptr, prop, values);
|
||||
|
||||
for (count = start; count < stop; count++) {
|
||||
fval = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, count - start));
|
||||
fval = PyFloat_AsDouble(value_items[count - start]);
|
||||
CLAMP(fval, min, max);
|
||||
values[count] = fval;
|
||||
}
|
||||
@@ -2693,7 +2695,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop,
|
||||
RNA_property_boolean_get_array(ptr, prop, values);
|
||||
|
||||
for (count = start; count < stop; count++)
|
||||
values[count] = PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count - start));
|
||||
values[count] = PyLong_AsLong(value_items[count - start]);
|
||||
|
||||
if (PyErr_Occurred()) ret = -1;
|
||||
else RNA_property_boolean_set_array(ptr, prop, values);
|
||||
@@ -2714,7 +2716,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop,
|
||||
RNA_property_int_get_array(ptr, prop, values);
|
||||
|
||||
for (count = start; count < stop; count++) {
|
||||
ival = PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count - start));
|
||||
ival = PyLong_AsLong(value_items[count - start]);
|
||||
CLAMP(ival, min, max);
|
||||
values[count] = ival;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user