[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31603] trunk/blender: speedup for pyrna boolean checking.
Campbell Barton
ideasman42 at gmail.com
Fri Aug 27 03:50:51 CEST 2010
Revision: 31603
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31603
Author: campbellbarton
Date: 2010-08-27 03:50:50 +0200 (Fri, 27 Aug 2010)
Log Message:
-----------
speedup for pyrna boolean checking.
if bpy.data.objects: ...
Would get loop over the entire collection, instead see if this collection has a single item.
Modified Paths:
--------------
trunk/blender/release/scripts/ui/space_info.py
trunk/blender/source/blender/python/intern/bpy_rna.c
Modified: trunk/blender/release/scripts/ui/space_info.py
===================================================================
--- trunk/blender/release/scripts/ui/space_info.py 2010-08-27 01:23:53 UTC (rev 31602)
+++ trunk/blender/release/scripts/ui/space_info.py 2010-08-27 01:50:50 UTC (rev 31603)
@@ -27,10 +27,6 @@
layout = self.layout
wm = context.manager
- if wm and wm.operators:
- last_op = wm.operators[-1]
- else:
- last_op = None
window = context.window
scene = context.scene
rd = scene.render
Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c 2010-08-27 01:23:53 UTC (rev 31602)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c 2010-08-27 01:50:50 UTC (rev 31603)
@@ -1255,6 +1255,25 @@
return RNA_property_collection_length(&self->ptr, self->prop);
}
+/* bool funcs are for speed, so we can avoid getting the length
+ * of 1000's of items in a linked list for eg. */
+static int pyrna_prop_array_bool(BPy_PropertyRNA *self)
+{
+ return RNA_property_array_length(&self->ptr, self->prop) ? 1 : 0;
+}
+
+static int pyrna_prop_collection_bool( BPy_PropertyRNA *self )
+{
+ /* no callback defined, just iterate and find the nth item */
+ CollectionPropertyIterator iter;
+ int test;
+
+ RNA_property_collection_begin(&self->ptr, self->prop, &iter);
+ test = iter.valid;
+ RNA_property_collection_end(&iter);
+ return test;
+}
+
/* internal use only */
static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_ssize_t keynum)
{
@@ -1647,6 +1666,31 @@
( objobjargproc ) NULL, /* mp_ass_subscript */
};
+/* only for fast bool's, large structs, assign nb_bool on init */
+static PyNumberMethods pyrna_prop_array_as_number = {
+ NULL, /* nb_add */
+ NULL, /* nb_subtract */
+ NULL, /* nb_multiply */
+ NULL, /* nb_remainder */
+ NULL, /* nb_divmod */
+ NULL, /* nb_power */
+ NULL, /* nb_negative */
+ NULL, /* nb_positive */
+ NULL, /* nb_absolute */
+ (inquiry) pyrna_prop_array_bool, /* nb_bool */
+};
+static PyNumberMethods pyrna_prop_collection_as_number = {
+ NULL, /* nb_add */
+ NULL, /* nb_subtract */
+ NULL, /* nb_multiply */
+ NULL, /* nb_remainder */
+ NULL, /* nb_divmod */
+ NULL, /* nb_power */
+ NULL, /* nb_negative */
+ NULL, /* nb_positive */
+ NULL, /* nb_absolute */
+ (inquiry) pyrna_prop_collection_bool, /* nb_bool */
+};
static int pyrna_prop_array_contains(BPy_PropertyRNA *self, PyObject *value)
{
@@ -3805,7 +3849,7 @@
/* Method suites for standard classes */
- NULL, /* PyNumberMethods *tp_as_number; */
+ &pyrna_prop_array_as_number, /* PyNumberMethods *tp_as_number; */
&pyrna_prop_array_as_sequence, /* PySequenceMethods *tp_as_sequence; */
&pyrna_prop_array_as_mapping, /* PyMappingMethods *tp_as_mapping; */
@@ -3885,7 +3929,7 @@
/* Method suites for standard classes */
- NULL, /* PyNumberMethods *tp_as_number; */
+ &pyrna_prop_collection_as_number, /* PyNumberMethods *tp_as_number; */
&pyrna_prop_collection_as_sequence, /* PySequenceMethods *tp_as_sequence; */
&pyrna_prop_collection_as_mapping, /* PyMappingMethods *tp_as_mapping; */
More information about the Bf-blender-cvs
mailing list