Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-08-19 14:38:34 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-08-19 14:38:34 +0400
commit2c1182664cb65e760742ed43fa840cd241d74b4a (patch)
tree4ca8bd4a3571fa5f3c7f8ef22803adb12dd706a1
parent561b49e9258f46229ccf5a2426d3deae01028ae3 (diff)
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).
-rw-r--r--source/blender/python/intern/bpy_rna.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index accc34152b5..1b8f986e71c 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -4297,6 +4297,27 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
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)
{
/* 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;
}
else if (kw != NULL) {
+#if 0
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)
kw_tot++; /* make sure invalid keywords are not given */