diff options
author | Erik <ecke101@gmail.com> | 2021-11-15 19:10:53 +0300 |
---|---|---|
committer | Erik <ecke101@gmail.com> | 2021-11-22 20:23:54 +0300 |
commit | 012917837649676e9ec4b9c2d7d4f7bdfd408739 (patch) | |
tree | c028b70718bf6312c5d7e64812d7198f7d867258 /source/blender/editors/interface/interface.c | |
parent | 55c82d8380ea3fd37a9d966fad10f42cc5b365d5 (diff) |
UI: Use a map for block name lookups
Use a map to speed up search for UI block names.
Time to redraw the node editor was decreased from
around 75-120ms to 40-70ms in a tree with many
Geometry Nodes.
Differential Revision: https://developer.blender.org/D13225
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r-- | source/blender/editors/interface/interface.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index c753c06b791..55fab04e9a4 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -37,6 +37,7 @@ #include "DNA_workspace_types.h" #include "BLI_alloca.h" +#include "BLI_ghash.h" #include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_rect.h" @@ -3521,22 +3522,35 @@ void UI_blocklist_draw(const bContext *C, const ListBase *lb) } /* can be called with C==NULL */ -void UI_blocklist_free(const bContext *C, ListBase *lb) +void UI_blocklist_free(const bContext *C, ARegion *region) { + ListBase *lb = ®ion->uiblocks; uiBlock *block; while ((block = BLI_pophead(lb))) { UI_block_free(C, block); } + if (region->runtime.block_name_map != NULL) { + BLI_ghash_free(region->runtime.block_name_map, NULL, NULL); + region->runtime.block_name_map = NULL; + } } -void UI_blocklist_free_inactive(const bContext *C, ListBase *lb) +void UI_blocklist_free_inactive(const bContext *C, ARegion *region) { + ListBase *lb = ®ion->uiblocks; + LISTBASE_FOREACH_MUTABLE (uiBlock *, block, lb) { if (!block->handle) { if (block->active) { block->active = false; } else { + if (region->runtime.block_name_map != NULL) { + uiBlock *b = BLI_ghash_lookup(region->runtime.block_name_map, block->name); + if (b == block) { + BLI_ghash_remove(region->runtime.block_name_map, b->name, NULL, NULL); + } + } BLI_remlink(lb, block); UI_block_free(C, block); } @@ -3552,7 +3566,10 @@ void UI_block_region_set(uiBlock *block, ARegion *region) /* each listbase only has one block with this name, free block * if is already there so it can be rebuilt from scratch */ if (lb) { - oldblock = BLI_findstring(lb, block->name, offsetof(uiBlock, name)); + if (region->runtime.block_name_map == NULL) { + region->runtime.block_name_map = BLI_ghash_str_new(__func__); + } + oldblock = (uiBlock *)BLI_ghash_lookup(region->runtime.block_name_map, block->name); if (oldblock) { oldblock->active = false; @@ -3562,6 +3579,7 @@ void UI_block_region_set(uiBlock *block, ARegion *region) /* at the beginning of the list! for dynamical menus/blocks */ BLI_addhead(lb, block); + BLI_ghash_reinsert(region->runtime.block_name_map, block->name, block, NULL, NULL); } block->oldblock = oldblock; |