From 5cd837a562d773cdff155ab05084af590341758d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 29 Dec 2009 15:40:26 +0000 Subject: * 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) --- source/blender/blenlib/BLI_listbase.h | 1 + source/blender/blenlib/BLI_math_vector.h | 16 ++++++++-------- source/blender/blenlib/intern/listbase.c | 20 ++++++++++++++++++++ source/blender/blenlib/intern/math_vector_inline.c | 16 ++++++++-------- 4 files changed, 37 insertions(+), 16 deletions(-) (limited to 'source/blender/blenlib') 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]; -- cgit v1.2.3