[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25609] trunk/blender/source: * speedup for animating bones, in one scene with sintel and a dragon animated its over 4x faster.

Campbell Barton ideasman42 at gmail.com
Tue Dec 29 16:40:26 CET 2009


Revision: 25609
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25609
Author:   campbellbarton
Date:     2009-12-29 16:40:26 +0100 (Tue, 29 Dec 2009)

Log Message:
-----------
* speedup for animating bones, in one scene with sintel and a dragon animated its over 4x faster.
* utility function BLI_findstring to avoid listbase lookup loops everywhere.
  eg: 
    ListBase *lb= objects= &CTX_data_main(C)->object;
    Object *ob= BLI_findstring(lb, name, offsetof(ID, name) + 2);

* made some more math functions use const's, (fix warnings I made in previous commits)

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_screen.h
    trunk/blender/source/blender/blenkernel/intern/action.c
    trunk/blender/source/blender/blenkernel/intern/library.c
    trunk/blender/source/blender/blenlib/BLI_listbase.h
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/intern/listbase.c
    trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/editors/space_logic/logic_window.c
    trunk/blender/source/blender/makesrna/intern/rna_pose.c
    trunk/blender/source/blender/python/generic/bpy_internal_import.c
    trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp

Modified: trunk/blender/source/blender/blenkernel/BKE_screen.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_screen.h	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/blenkernel/BKE_screen.h	2009-12-29 15:40:26 UTC (rev 25609)
@@ -220,8 +220,6 @@
 void BKE_spacetype_register(struct SpaceType *st);
 void BKE_spacetypes_free(void);	/* only for quitting blender */
 
-// MenuType *BKE_spacemenu_find(const char *idname, int spacetype);
-
 /* spacedata */
 void BKE_spacedata_freelist(ListBase *lb);
 void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2);

Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/blenkernel/intern/action.c	2009-12-29 15:40:26 UTC (rev 25609)
@@ -379,19 +379,10 @@
 /* usually used within a loop, so we got a N^2 slowdown */
 bPoseChannel *get_pose_channel(const bPose *pose, const char *name)
 {
-	bPoseChannel *chan;
-	
 	if (ELEM(NULL, pose, name) || (name[0] == 0))
 		return NULL;
 	
-	for (chan=pose->chanbase.first; chan; chan=chan->next) {
-		if (chan->name[0] == name[0]) {
-			if (!strcmp (chan->name, name))
-				return chan;
-		}
-	}
-
-	return NULL;
+	return BLI_findstring(&pose->chanbase, name, offsetof(bPoseChannel, name));
 }
 
 /* Use with care, not on Armature poses but for temporal ones */

Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/blenkernel/intern/library.c	2009-12-29 15:40:26 UTC (rev 25609)
@@ -38,6 +38,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stddef.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -844,18 +845,8 @@
 
 ID *find_id(char *type, char *name)		/* type: "OB" or "MA" etc */
 {
-	ID *id;
-	ListBase *lb;
-	
-	lb= wich_libbase(G.main, GS(type));
-	
-	id= lb->first;
-	while(id) {
-		if(id->name[2]==name[0] && strcmp(id->name+2, name)==0 ) 
-			return id;
-		id= id->next;
-	}
-	return 0;
+	ListBase *lb= wich_libbase(G.main, GS(type));
+	return BLI_findstring(lb, name, offsetof(ID, name) + 2);
 }
 
 static void get_flags_for_id(ID *id, char *buf) 
@@ -1336,11 +1327,7 @@
 	if(lb==0) return;
 	
 	/* search for id */
-	idtest= lb->first;
-	while(idtest) {
-		if( strcmp(idtest->name+2, name)==0) break;
-		idtest= idtest->next;
-	}
+	idtest= BLI_findstring(lb, name, offsetof(ID, name) + 2);
 
 	if(idtest) if( new_id(lb, idtest, name)==0 ) sort_alpha_id(lb, idtest);
 }

Modified: trunk/blender/source/blender/blenlib/BLI_listbase.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_listbase.h	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/blenlib/BLI_listbase.h	2009-12-29 15:40:26 UTC (rev 25609)
@@ -44,6 +44,7 @@
 void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
 void *BLI_findlink(struct ListBase *listbase, int number);
 int BLI_findindex(struct ListBase *listbase, void *vlink);
+void *BLI_findstring(struct ListBase *listbase, const char *id, int offset);
 void BLI_freelistN(struct ListBase *listbase);
 void BLI_addtail(struct ListBase *listbase, void *vlink);
 void BLI_remlink(struct ListBase *listbase, void *vlink);

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2009-12-29 15:40:26 UTC (rev 25609)
@@ -81,22 +81,22 @@
 MINLINE void madd_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]);
 
 MINLINE void negate_v3(float r[3]);
-MINLINE void negate_v3_v3(float r[3], float a[3]);
+MINLINE void negate_v3_v3(float r[3], const float a[3]);
 
-MINLINE float dot_v2v2(float a[2], float b[2]); 
-MINLINE float dot_v3v3(float a[3], float b[3]);
+MINLINE float dot_v2v2(const float a[2], const float b[2]);
+MINLINE float dot_v3v3(const float a[3], const float b[3]);
 
-MINLINE float cross_v2v2(float a[2], float b[2]);
+MINLINE float cross_v2v2(const float a[2], const float b[2]);
 MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]);
 
 MINLINE void star_m3_v3(float R[3][3],float a[3]);
 
 /*********************************** Length **********************************/
 
-MINLINE float len_v2(float a[2]);
-MINLINE float len_v2v2(float a[2], float b[2]);
-MINLINE float len_v3(float a[3]);
-MINLINE float len_v3v3(float a[3], float b[3]);
+MINLINE float len_v2(const float a[2]);
+MINLINE float len_v2v2(const float a[2], const float b[2]);
+MINLINE float len_v3(const float a[3]);
+MINLINE float len_v3v3(const float a[3], const float b[3]);
 
 MINLINE float normalize_v2(float r[2]);
 MINLINE float normalize_v3(float r[3]);

Modified: trunk/blender/source/blender/blenlib/intern/listbase.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/listbase.c	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/blenlib/intern/listbase.c	2009-12-29 15:40:26 UTC (rev 25609)
@@ -343,6 +343,26 @@
 	return -1;
 }
 
+void *BLI_findstring(ListBase *listbase, const char *id, int offset)
+{
+	Link *link= NULL;
+	const char *id_iter;
+
+	if (listbase == NULL) return NULL;
+
+	link= listbase->first;
+	while (link) {
+		id_iter= ((const char *)link) + offset;
+		printf("ASS '%s'\n", id_iter);
+		if(id[0] == id_iter[0] && strcmp(id, id_iter)==0)
+			return link;
+
+		link= link->next;
+	}
+
+	return NULL;
+}
+
 void BLI_duplicatelist(ListBase *list1, const ListBase *list2)
 {
 	struct Link *link1, *link2;

Modified: trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2009-12-29 15:40:26 UTC (rev 25609)
@@ -194,24 +194,24 @@
 	r[2]= -r[2];
 }
 
-MINLINE void negate_v3_v3(float r[3], float a[3])
+MINLINE void negate_v3_v3(float r[3], const float a[3])
 {
 	r[0]= -a[0];
 	r[1]= -a[1];
 	r[2]= -a[2];
 }
 
-MINLINE float dot_v2v2(float *a, float *b)
+MINLINE float dot_v2v2(const float a[2], const float b[2])
 {
 	return a[0]*b[0] + a[1]*b[1];
 }
 
-MINLINE float dot_v3v3(float a[3], float b[3])
+MINLINE float dot_v3v3(const float a[3], const float b[3])
 {
 	return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
 }
 
-MINLINE float cross_v2v2(float a[2], float b[2])
+MINLINE float cross_v2v2(const float a[2], const float b[2])
 {
 	 return a[0]*b[1] - a[1]*b[0];
 }
@@ -236,12 +236,12 @@
 
 /*********************************** Length **********************************/
 
-MINLINE float len_v2(float *v)
+MINLINE float len_v2(const float v[2])
 {
 	return (float)sqrt(v[0]*v[0] + v[1]*v[1]);
 }
 
-MINLINE float len_v2v2(float *v1, float *v2)
+MINLINE float len_v2v2(const float v1[2], const float v2[2])
 {
 	float x, y;
 
@@ -250,12 +250,12 @@
 	return (float)sqrt(x*x+y*y);
 }
 
-MINLINE float len_v3(float a[3])
+MINLINE float len_v3(const float a[3])
 {
 	return sqrtf(dot_v3v3(a, a));
 }
 
-MINLINE float len_v3v3(float a[3], float b[3])
+MINLINE float len_v3v3(const float a[3], const float b[3])
 {
 	float d[3];
 

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c	2009-12-29 15:40:26 UTC (rev 25609)
@@ -23,6 +23,7 @@
  */
 
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 
 #include "MEM_guardedalloc.h"
@@ -920,18 +921,11 @@
 
 static void test_obpoin_but(bContext *C, char *name, ID **idpp)
 {
-	ID *id;
+	ID *id= BLI_findstring(&CTX_data_main(C)->object, name, offsetof(ID, name) + 2);
+	*idpp= id; /* can be NULL */
 	
-	id= CTX_data_main(C)->object.first;
-	while(id) {
-		if( strcmp(name, id->name+2)==0 ) {
-			*idpp= id;
-			id_lib_extern(id);	/* checks lib data, sets correct flag for saving then */
-			return;
-		}
-		id= id->next;
-	}
-	*idpp= NULL;
+	if(id)
+		id_lib_extern(id);	/* checks lib data, sets correct flag for saving then */
 }
 
 /* draw panel showing settings for a constraint */

Modified: trunk/blender/source/blender/editors/space_logic/logic_window.c
===================================================================
--- trunk/blender/source/blender/editors/space_logic/logic_window.c	2009-12-29 12:53:30 UTC (rev 25608)
+++ trunk/blender/source/blender/editors/space_logic/logic_window.c	2009-12-29 15:40:26 UTC (rev 25609)
@@ -975,107 +975,45 @@
 
 static void test_scriptpoin_but(struct bContext *C, char *name, ID **idpp)
 {
-	ID *id;
-	
-	id= CTX_data_main(C)->text.first;
-	while(id) {
-		if( strcmp(name, id->name+2)==0 ) {
-			*idpp= id;
-			return;
-		}
-		id= id->next;
-	}
-	*idpp= NULL;
+	*idpp= BLI_findstring(&CTX_data_main(C)->text, name, offsetof(ID, name) + 2);
 }
 
 static void test_actionpoin_but(struct bContext *C, char *name, ID **idpp)
 {
-	ID *id;
-	
-	id= CTX_data_main(C)->action.first;
-	while(id) {
-		if( strcmp(name, id->name+2)==0 ) {
-			id_us_plus(id);
-			*idpp= id;
-			return;
-		}
-		id= id->next;
-	}
-	*idpp= NULL;
+	*idpp= BLI_findstring(&CTX_data_main(C)->text, name, offsetof(ID, name) + 2);
+	if(*idpp)
+		id_us_plus(*idpp);
 }
 
 
 static void test_obpoin_but(struct bContext *C, char *name, ID **idpp)
 {
-	ID *id;
-	
-	id= CTX_data_main(C)->object.first;
-	while(id) {
-		if( strcmp(name, id->name+2)==0 ) {
-			*idpp= id;
-			id_lib_extern(id);	/* checks lib data, sets correct flag for saving then */
-			return;
-		}
-		id= id->next;
-	}
-	*idpp= NULL;
+	*idpp= BLI_findstring(&CTX_data_main(C)->object, name, offsetof(ID, name) + 2);
+	if(*idpp)
+		id_lib_extern(*idpp);	/* checks lib data, sets correct flag for saving then */
 }
 
 static void test_meshpoin_but(struct bContext *C, char *name, ID **idpp)
 {
-	ID *id;
-
-	if( *idpp ) (*idpp)->us--;
-	
-	id= CTX_data_main(C)->mesh.first;
-	while(id) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list