[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35121] trunk/blender/source/blender/ python/intern: found moving verts in pythons 2. 5 api is approx 10x slower because the multi-dimensional array assignment reads the array 3 times (typecheck, length-check & for-real).

Campbell Barton ideasman42 at gmail.com
Thu Feb 24 09:47:58 CET 2011


Revision: 35121
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35121
Author:   campbellbarton
Date:     2011-02-24 08:47:58 +0000 (Thu, 24 Feb 2011)
Log Message:
-----------
found moving verts in pythons 2.5 api is approx 10x slower because the multi-dimensional array assignment reads the array 3 times (typecheck, length-check & for-real).

the length check was running sequence checks on every number which would fail, small speedup by avoiding this.

should eventually get this working faster by reading once into an allocated array.

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

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2011-02-24 07:25:47 UTC (rev 35120)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2011-02-24 08:47:58 UTC (rev 35121)
@@ -1042,20 +1042,12 @@
 
 
 	if (RNA_property_array_check(ptr, prop)) {
-
-		/* char error_str[512]; */
 		int ok= 1;
 
-//		if (!PySequence_Check(value)) {
-//			PyErr_Format(PyExc_TypeError, "%.200s RNA array assignment to %.200s.%.200s expected a sequence, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
-//			return -1;
-//		}
-
 		/* done getting the length */
 		ok= pyrna_py_to_array(ptr, prop, data, value, error_prefix);
 
 		if (!ok) {
-			/* PyErr_Format(PyExc_AttributeError, "%.200s %s", error_prefix, error_str); */
 			return -1;
 		}
 	}

Modified: trunk/blender/source/blender/python/intern/bpy_rna_array.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna_array.c	2011-02-24 07:25:47 UTC (rev 35120)
+++ trunk/blender/source/blender/python/intern/bpy_rna_array.c	2011-02-24 08:47:58 UTC (rev 35121)
@@ -110,21 +110,22 @@
 }
 
 /* Returns the number of items in a single- or multi-dimensional sequence. */
-static int count_items(PyObject *seq)
+static int count_items(PyObject *seq, int dim)
 {
 	int totitem= 0;
 
-	if (PySequence_Check(seq)) {
+	if(dim > 1) {
 		const int seq_size= PySequence_Size(seq);
 		int i;
 		for (i= 0; i < seq_size; i++) {
 			PyObject *item= PySequence_GetItem(seq, i);
-			totitem += count_items(item);
+			totitem += count_items(item, dim - 1);
 			Py_DECREF(item);
 		}
 	}
-	else
-		totitem= 1;
+	else {
+		totitem= PySequence_Size(seq);
+	}
 
 	return totitem;
 }
@@ -135,8 +136,8 @@
 	int dimsize[MAX_ARRAY_DIMENSION];
 	int tot, totdim, len;
 
-	tot= count_items(rvalue);
 	totdim= RNA_property_array_dimension(ptr, prop, dimsize);
+	tot= count_items(rvalue, totdim);
 
 	if ((RNA_property_flag(prop) & PROP_DYNAMIC) && lvalue_dim == 0) {
 		if (RNA_property_array_length(ptr, prop) != tot) {




More information about the Bf-blender-cvs mailing list