minor speedup to python/rna api keyword argument lookups.
- dont use hash lookups in this case because converting the string to unicode and doing a hash lookup is slower then looping over the keys and comparing (which avoids creating and throwning away a unicode string).
This commit is contained in:
@@ -4297,6 +4297,27 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use to replace PyDict_GetItemString() when the overhead of converting a
|
||||||
|
* string into a python unicode is higher than a non hash lookup.
|
||||||
|
* works on small dict's such as keyword args. */
|
||||||
|
static PyObject *small_dict_get_item_string(PyObject *dict, const char *key_lookup)
|
||||||
|
{
|
||||||
|
PyObject *key= NULL;
|
||||||
|
Py_ssize_t pos = 0;
|
||||||
|
PyObject *value = NULL;
|
||||||
|
|
||||||
|
/* case not, search for it in the script's global dictionary */
|
||||||
|
while (PyDict_Next(dict, &pos, &key, &value)) {
|
||||||
|
if(PyUnicode_Check(key)) {
|
||||||
|
if(strcmp(key_lookup, _PyUnicode_AsString(key))==0) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject *kw)
|
static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject *kw)
|
||||||
{
|
{
|
||||||
/* Note, both BPy_StructRNA and BPy_PropertyRNA can be used here */
|
/* Note, both BPy_StructRNA and BPy_PropertyRNA can be used here */
|
||||||
@@ -4391,7 +4412,11 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
|
|||||||
kw_arg= FALSE;
|
kw_arg= FALSE;
|
||||||
}
|
}
|
||||||
else if (kw != NULL) {
|
else if (kw != NULL) {
|
||||||
|
#if 0
|
||||||
item= PyDict_GetItemString(kw, RNA_property_identifier(parm)); /* borrow ref */
|
item= PyDict_GetItemString(kw, RNA_property_identifier(parm)); /* borrow ref */
|
||||||
|
#else
|
||||||
|
item= small_dict_get_item_string(kw, RNA_property_identifier(parm)); /* borrow ref */
|
||||||
|
#endif
|
||||||
if(item)
|
if(item)
|
||||||
kw_tot++; /* make sure invalid keywords are not given */
|
kw_tot++; /* make sure invalid keywords are not given */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user