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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-12-29 18:40:26 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-12-29 18:40:26 +0300
commit5cd837a562d773cdff155ab05084af590341758d (patch)
tree20609a23f562cbf8ccf91b41af3f80240551b977 /source/blender
parentd5cef9a30d1febb22b760eb7d5cdac0fd628bb06 (diff)
* 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)
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_screen.h2
-rw-r--r--source/blender/blenkernel/intern/action.c11
-rw-r--r--source/blender/blenkernel/intern/library.c21
-rw-r--r--source/blender/blenlib/BLI_listbase.h1
-rw-r--r--source/blender/blenlib/BLI_math_vector.h16
-rw-r--r--source/blender/blenlib/intern/listbase.c20
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c16
-rw-r--r--source/blender/editors/interface/interface_templates.c16
-rw-r--r--source/blender/editors/space_logic/logic_window.c94
-rw-r--r--source/blender/makesrna/intern/rna_pose.c14
-rw-r--r--source/blender/python/generic/bpy_internal_import.c14
11 files changed, 80 insertions, 145 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index c9d1caa1cfe..21150af7144 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -220,8 +220,6 @@ const struct ListBase *BKE_spacetypes_list(void);
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);
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 303cd208b7c..9e89ae77caa 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -379,19 +379,10 @@ bActionGroup *action_groups_find_named (bAction *act, const char name[])
/* 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 */
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index a32746e3093..c38cfe4ee27 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -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 @@ void free_main(Main *mainvar)
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 @@ void test_idbutton(char *name)
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);
}
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index bd735888f95..f4841762227 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -44,6 +44,7 @@ void addlisttolist(struct ListBase *list1, struct ListBase *list2);
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);
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 26e7ff5abe9..4dbef4ef07c 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -81,22 +81,22 @@ MINLINE void madd_v3_v3v3fl(float r[3], float a[3], float b[3], float f);
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]);
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
index 166f4ed029e..9b4e1720d8b 100644
--- a/source/blender/blenlib/intern/listbase.c
+++ b/source/blender/blenlib/intern/listbase.c
@@ -343,6 +343,26 @@ int BLI_findindex(ListBase *listbase, void *vlink)
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;
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 16f35dbc5fa..8b09cb86d3a 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -194,24 +194,24 @@ MINLINE void negate_v3(float r[3])
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 @@ MINLINE void star_m3_v3(float mat[][3], float *vec)
/*********************************** 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 @@ MINLINE float len_v2v2(float *v1, float *v2)
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];
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 7bad3ee0ecd..a2b926003a7 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -23,6 +23,7 @@
*/
#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
#include "MEM_guardedalloc.h"
@@ -920,18 +921,11 @@ static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short
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 */
diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c
index 8ba0577e3c7..dfc9b263ac2 100644
--- a/source/blender/editors/space_logic/logic_window.c
+++ b/source/blender/editors/space_logic/logic_window.c
@@ -975,107 +975,45 @@ static void verify_logicbutton_func(bContext *C, void *data1, void *data2)
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) {
- if( strcmp(name, id->name+2)==0 ) {
- *idpp= id;
- id_us_plus(id);
- return;
- }
- id= id->next;
- }
- *idpp= NULL;
+ *idpp= BLI_findstring(&CTX_data_main(C)->mesh, name, offsetof(ID, name) + 2);
+ if(*idpp)
+ id_us_plus(*idpp);
}
static void test_matpoin_but(struct bContext *C, char *name, ID **idpp)
{
- ID *id;
-
- if( *idpp ) (*idpp)->us--;
-
- id= CTX_data_main(C)->mat.first;
- while(id) {
- if( strcmp(name, id->name+2)==0 ) {
- *idpp= id;
- id_us_plus(id);
- return;
- }
- id= id->next;
- }
- *idpp= NULL;
+ *idpp= BLI_findstring(&CTX_data_main(C)->mat, name, offsetof(ID, name) + 2);
+ if(*idpp)
+ id_us_plus(*idpp);
}
static void test_scenepoin_but(struct bContext *C, char *name, ID **idpp)
{
- ID *id;
-
- if( *idpp ) (*idpp)->us--;
-
- id= CTX_data_main(C)->scene.first;
- while(id) {
- if( strcmp(name, id->name+2)==0 ) {
- *idpp= id;
- id_us_plus(id);
- return;
- }
- id= id->next;
- }
- *idpp= NULL;
+ *idpp= BLI_findstring(&CTX_data_main(C)->scene, name, offsetof(ID, name) + 2);
+ if(*idpp)
+ id_us_plus(*idpp);
}
-
static void test_keyboard_event(struct bContext *C, void *arg_ks, void *arg_unused)
{
bKeyboardSensor *ks= (bKeyboardSensor*)arg_ks;
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index 7e2b9d7875b..07c4445872e 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -58,6 +58,8 @@
#include "MEM_guardedalloc.h"
+#include "RNA_access.h"
+
static void rna_Pose_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
// XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
@@ -509,6 +511,16 @@ static int rna_PoseChannel_rotation_4d_editable(PointerRNA *ptr, int index)
return PROP_EDITABLE;
}
+/* not essential, but much faster then the default lookup function */
+PointerRNA rna_PoseBones_lookup_string(PointerRNA *ptr, const char *key)
+{
+ PointerRNA rptr;
+ bPose *pose= (bPose*)ptr->data;
+ bPoseChannel *pchan= BLI_findstring(&pose->chanbase, key, offsetof(bPoseChannel, name));
+ RNA_pointer_create(ptr->id.data, &RNA_PoseBone, pchan, &rptr);
+ return rptr;
+}
+
#else
static void rna_def_bone_group(BlenderRNA *brna)
@@ -1077,7 +1089,7 @@ static void rna_def_pose(BlenderRNA *brna)
RNA_def_property_collection_sdna(prop, NULL, "chanbase", NULL);
RNA_def_property_struct_type(prop, "PoseBone");
RNA_def_property_ui_text(prop, "Pose Bones", "Individual pose bones for the armature.");
-
+ RNA_def_property_collection_funcs(prop, 0, 0, 0, 0, 0, 0, "rna_PoseBones_lookup_string"); /* can be removed, only for fast lookup */
/* bone groups */
prop= RNA_def_property(srna, "bone_groups", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "agroups", NULL);
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c
index 002467687c4..e890dc11f05 100644
--- a/source/blender/python/generic/bpy_internal_import.c
+++ b/source/blender/python/generic/bpy_internal_import.c
@@ -33,6 +33,8 @@
#include "MEM_guardedalloc.h"
#include "BKE_text.h" /* txt_to_buf */
#include "BKE_main.h"
+#include "BLI_listbase.h"
+#include <stddef.h>
static Main *bpy_import_main= NULL;
@@ -100,10 +102,7 @@ PyObject *bpy_text_import_name( char *name, int *found )
memcpy( txtname, name, namelen );
memcpy( &txtname[namelen], ".py", 4 );
- for(text = maggie->text.first; text; text = text->id.next) {
- if( !strcmp( txtname, text->id.name+2 ) )
- break;
- }
+ text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
if( !text )
return NULL;
@@ -142,12 +141,7 @@ PyObject *bpy_text_reimport( PyObject *module, int *found )
return NULL;
/* look up the text object */
- text = ( Text * ) & ( maggie->text.first );
- while( text ) {
- if( !strcmp( txtname, text->id.name+2 ) )
- break;
- text = text->id.next;
- }
+ text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
/* uh-oh.... didn't find it */
if( !text )