Revision: 39549
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39549
Author:   campbellbarton
Date:     2011-08-19 10:38:34 +0000 (Fri, 19 Aug 2011)
Log Message:
-----------
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).

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c        2011-08-19 
10:35:47 UTC (rev 39548)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c        2011-08-19 
10:38:34 UTC (rev 39549)
@@ -4297,6 +4297,27 @@
        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 @@
                        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 */
 

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to