diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-08-11 10:06:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-08-11 10:06:17 +0400 |
commit | a7663cc37753abd97744b51739358fb6b8026883 (patch) | |
tree | 5fe4e6bd695d42f47027c40c630f918bdec33294 /source/blender/windowmanager/intern/wm.c | |
parent | 0fac849d44d5bf8f2d3add9e10c03adbe5ffe331 (diff) |
use ghash for operator and menu types, was doing string lookup in the operator list (containing over 1000 items) for each button draw.
gives small speedup for UI drawing and overall startup time.
Diffstat (limited to 'source/blender/windowmanager/intern/wm.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 1d5cf1cdc53..9299b50103c 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -40,7 +40,11 @@ #include "GHOST_C-api.h" +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" #include "BLI_blenlib.h" +#include "BLI_ghash.h" #include "BKE_blender.h" #include "BKE_context.h" @@ -59,8 +63,6 @@ #include "wm_draw.h" #include "wm.h" -#include "MEM_guardedalloc.h" - #include "ED_screen.h" #ifdef WITH_PYTHON @@ -151,14 +153,14 @@ void WM_operator_stack_clear(wmWindowManager *wm) /* ****************************************** */ -static ListBase menutypes = {NULL, NULL}; /* global menutype list */ +static GHash *menutypes_hash= NULL; MenuType *WM_menutype_find(const char *idname, int quiet) { MenuType* mt; if (idname[0]) { - mt= BLI_findstring(&menutypes, idname, offsetof(MenuType, idname)); + mt= BLI_ghash_lookup(menutypes_hash, idname); if(mt) return mt; } @@ -171,35 +173,55 @@ MenuType *WM_menutype_find(const char *idname, int quiet) int WM_menutype_add(MenuType* mt) { - BLI_addtail(&menutypes, mt); + BLI_ghash_insert(menutypes_hash, (void *)mt->idname, mt); return 1; } /* inefficient but only used for tooltip code */ int WM_menutype_contains(MenuType* mt) { - return (mt != NULL && BLI_findindex(&menutypes, mt) != -1); + int found= FALSE; + + if(mt) { + GHashIterator *iter= BLI_ghashIterator_new(menutypes_hash); + + for( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) { + if(mt == BLI_ghashIterator_getValue(iter)) { + found= TRUE; + break; + } + } + BLI_ghashIterator_free(iter); + } + + return found; } void WM_menutype_freelink(MenuType* mt) { - BLI_freelinkN(&menutypes, mt); + BLI_ghash_remove(menutypes_hash, mt->idname, NULL, (GHashValFreeFP)MEM_freeN); } -void WM_menutype_free(void) +/* called on initialize WM_init() */ +void WM_menutype_init(void) { - MenuType* mt= menutypes.first, *mt_next; + menutypes_hash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "menutypes_hash gh"); +} - while(mt) { - mt_next= mt->next; +void WM_menutype_free(void) +{ + GHashIterator *iter= BLI_ghashIterator_new(menutypes_hash); - if(mt->ext.free) + for( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) { + MenuType *mt= BLI_ghashIterator_getValue(iter); + if(mt->ext.free) { mt->ext.free(mt->ext.data); - - WM_menutype_freelink(mt); - - mt= mt_next; + } } + BLI_ghashIterator_free(iter); + + BLI_ghash_free(menutypes_hash, NULL, (GHashValFreeFP)MEM_freeN); + menutypes_hash= NULL; } /* ****************************************** */ |