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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-08-27 05:50:50 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-08-27 05:50:50 +0400
commit6d195f61953fb9fa9c65514944f992c620bd449f (patch)
tree4b2634281c4071db316b8d05df0b728160d7a8fc /source
parent9d2b1af0a1aadb30a7be2f7a0ffe360e45a1e740 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/intern/bpy_rna.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 84ce38c3c77..3bce1f83d6e 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -1255,6 +1255,25 @@ static Py_ssize_t pyrna_prop_collection_length( BPy_PropertyRNA *self )
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 @@ static PyMappingMethods pyrna_prop_collection_as_mapping = {
( 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 @@ PyTypeObject pyrna_prop_array_Type = {
/* 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 @@ PyTypeObject pyrna_prop_collection_Type = {
/* 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; */