forked from bartvdbraak/blender
use ghash for DNA_struct_find_nr(), gives ~18% speedup on loading sintel lite, will also speedup undo.
note: only works with CMake, wasn't able to get this working with scons, complains about same file being built in different environments.
This commit is contained in:
parent
a0a96a84fe
commit
d4dec1c3bc
@ -55,6 +55,9 @@ typedef struct SDNA {
|
|||||||
(sp[2], sp[3]), (sp[4], sp[5]), .. are the member
|
(sp[2], sp[3]), (sp[4], sp[5]), .. are the member
|
||||||
type and name numbers respectively */
|
type and name numbers respectively */
|
||||||
|
|
||||||
|
struct GHash *structs_map; /* ghash for faster lookups,
|
||||||
|
requires WITH_DNA_GHASH to be used for now */
|
||||||
|
|
||||||
/* wrong place for this really, its a simple
|
/* wrong place for this really, its a simple
|
||||||
* cache for findstruct_nr.
|
* cache for findstruct_nr.
|
||||||
*/
|
*/
|
||||||
|
@ -27,12 +27,17 @@
|
|||||||
|
|
||||||
# message(STATUS "Configuring makesdna")
|
# message(STATUS "Configuring makesdna")
|
||||||
|
|
||||||
|
# add_definitions(-DWITH_DNA_GHASH)
|
||||||
|
|
||||||
blender_include_dirs(
|
blender_include_dirs(
|
||||||
../../../../intern/guardedalloc
|
../../../../intern/guardedalloc
|
||||||
../../blenloader
|
../../blenloader
|
||||||
|
../../blenlib
|
||||||
..
|
..
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
# Build makesdna executable
|
# Build makesdna executable
|
||||||
set(SRC
|
set(SRC
|
||||||
makesdna.c
|
makesdna.c
|
||||||
@ -56,6 +61,8 @@ add_custom_command(
|
|||||||
DEPENDS makesdna
|
DEPENDS makesdna
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
# Build bf_dna library
|
# Build bf_dna library
|
||||||
set(INC
|
set(INC
|
||||||
|
|
||||||
@ -72,3 +79,22 @@ set(SRC
|
|||||||
)
|
)
|
||||||
|
|
||||||
blender_add_lib(bf_dna "${SRC}" "${INC}" "${INC_SYS}")
|
blender_add_lib(bf_dna "${SRC}" "${INC}" "${INC_SYS}")
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Build bf_dna_blenlib library
|
||||||
|
set(INC
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
set(INC_SYS
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
set(SRC
|
||||||
|
../../blenlib/intern/BLI_mempool.c
|
||||||
|
../../blenlib/intern/listbase.c
|
||||||
|
../../blenlib/intern/BLI_ghash.c
|
||||||
|
)
|
||||||
|
|
||||||
|
blender_add_lib(bf_dna_blenlib "${SRC}" "${INC}" "${INC_SYS}")
|
||||||
|
@ -67,5 +67,6 @@ else:
|
|||||||
else:
|
else:
|
||||||
dna.Command ('dna.c', '', root_build_dir+os.sep+"makesdna.exe $TARGET")
|
dna.Command ('dna.c', '', root_build_dir+os.sep+"makesdna.exe $TARGET")
|
||||||
|
|
||||||
|
# TODO, get WITH_DNA_GHASH working, see CMake's 'WITH_DNA_GHASH'
|
||||||
obj = ['intern/dna.c', 'intern/dna_genfile.c']
|
obj = ['intern/dna.c', 'intern/dna_genfile.c']
|
||||||
Return ('obj')
|
Return ('obj')
|
||||||
|
@ -42,6 +42,10 @@
|
|||||||
|
|
||||||
#include "MEM_guardedalloc.h" // for MEM_freeN MEM_mallocN MEM_callocN
|
#include "MEM_guardedalloc.h" // for MEM_freeN MEM_mallocN MEM_callocN
|
||||||
|
|
||||||
|
#ifdef WITH_DNA_GHASH
|
||||||
|
# include "BLI_ghash.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "DNA_genfile.h"
|
#include "DNA_genfile.h"
|
||||||
#include "DNA_sdna_types.h" // for SDNA ;-)
|
#include "DNA_sdna_types.h" // for SDNA ;-)
|
||||||
|
|
||||||
@ -198,6 +202,10 @@ void DNA_sdna_free(SDNA *sdna)
|
|||||||
MEM_freeN(sdna->types);
|
MEM_freeN(sdna->types);
|
||||||
MEM_freeN(sdna->structs);
|
MEM_freeN(sdna->structs);
|
||||||
|
|
||||||
|
#ifdef WITH_DNA_GHASH
|
||||||
|
BLI_ghash_free(sdna->structs_map, NULL, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
MEM_freeN(sdna);
|
MEM_freeN(sdna);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,13 +283,18 @@ static short *findstruct_name(SDNA *sdna, const char *str)
|
|||||||
int DNA_struct_find_nr(SDNA *sdna, const char *str)
|
int DNA_struct_find_nr(SDNA *sdna, const char *str)
|
||||||
{
|
{
|
||||||
short *sp= NULL;
|
short *sp= NULL;
|
||||||
int a;
|
|
||||||
|
|
||||||
if(sdna->lastfind<sdna->nr_structs) {
|
if(sdna->lastfind<sdna->nr_structs) {
|
||||||
sp= sdna->structs[sdna->lastfind];
|
sp= sdna->structs[sdna->lastfind];
|
||||||
if(strcmp( sdna->types[ sp[0] ], str )==0) return sdna->lastfind;
|
if(strcmp( sdna->types[ sp[0] ], str )==0) return sdna->lastfind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_DNA_GHASH
|
||||||
|
return (intptr_t)BLI_ghash_lookup(sdna->structs_map, str) - 1;
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
|
||||||
for(a=0; a<sdna->nr_structs; a++) {
|
for(a=0; a<sdna->nr_structs; a++) {
|
||||||
|
|
||||||
sp= sdna->structs[a];
|
sp= sdna->structs[a];
|
||||||
@ -291,8 +304,9 @@ int DNA_struct_find_nr(SDNA *sdna, const char *str)
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************* END DIV ********************** */
|
/* ************************* END DIV ********************** */
|
||||||
@ -481,6 +495,16 @@ static void init_structDNA(SDNA *sdna, int do_endian_swap)
|
|||||||
sp[10]= 9;
|
sp[10]= 9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_DNA_GHASH
|
||||||
|
/* create a ghash lookup to speed up */
|
||||||
|
sdna->structs_map= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "init_structDNA gh");
|
||||||
|
|
||||||
|
for(nr = 0; nr < sdna->nr_structs; nr++) {
|
||||||
|
sp= sdna->structs[nr];
|
||||||
|
BLI_ghash_insert(sdna->structs_map, (void *)sdna->types[sp[0]], (void *)(nr + 1));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,6 +243,7 @@ blender_include_dirs_sys(
|
|||||||
|
|
||||||
add_executable(makesrna ${SRC} ${SRC_RNA_INC} ${SRC_DNA_INC})
|
add_executable(makesrna ${SRC} ${SRC_RNA_INC} ${SRC_DNA_INC})
|
||||||
target_link_libraries(makesrna bf_dna)
|
target_link_libraries(makesrna bf_dna)
|
||||||
|
target_link_libraries(makesrna bf_dna_blenlib)
|
||||||
|
|
||||||
# Output rna_*_gen.c
|
# Output rna_*_gen.c
|
||||||
# note (linux only): with crashes try add this after COMMAND: valgrind --leak-check=full --track-origins=yes
|
# note (linux only): with crashes try add this after COMMAND: valgrind --leak-check=full --track-origins=yes
|
||||||
|
Loading…
Reference in New Issue
Block a user