writefile: reuse SDNA between writes
Avoids decoding the SDNA string every undo step.
This commit is contained in:
@@ -1080,13 +1080,9 @@ static FileData *filedata_new(void)
|
||||
|
||||
fd->filedes = -1;
|
||||
fd->gzfiledes = NULL;
|
||||
|
||||
/* XXX, this doesn't need to be done all the time,
|
||||
* but it keeps us re-entrant, remove once we have
|
||||
* a lib that provides a nice lock. - zr
|
||||
*/
|
||||
fd->memsdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, NULL);
|
||||
|
||||
|
||||
fd->memsdna = DNA_sdna_current_get();
|
||||
|
||||
fd->datamap = oldnewmap_new();
|
||||
fd->globmap = oldnewmap_new();
|
||||
fd->libmap = oldnewmap_new();
|
||||
@@ -1280,9 +1276,7 @@ void blo_freefiledata(FileData *fd)
|
||||
|
||||
// Free all BHeadN data blocks
|
||||
BLI_freelistN(&fd->listbase);
|
||||
|
||||
if (fd->memsdna)
|
||||
DNA_sdna_free(fd->memsdna);
|
||||
|
||||
if (fd->filesdna)
|
||||
DNA_sdna_free(fd->filesdna);
|
||||
if (fd->compflags)
|
||||
|
||||
@@ -74,7 +74,7 @@ typedef struct FileData {
|
||||
|
||||
// general reading variables
|
||||
struct SDNA *filesdna;
|
||||
struct SDNA *memsdna;
|
||||
const struct SDNA *memsdna;
|
||||
char *compflags; /* array of eSDNA_StructCompare */
|
||||
|
||||
int fileversion;
|
||||
|
||||
@@ -303,7 +303,7 @@ static void ww_handle_init(eWriteWrapType ww_type, WriteWrap *r_ww)
|
||||
|
||||
|
||||
typedef struct {
|
||||
struct SDNA *sdna;
|
||||
const struct SDNA *sdna;
|
||||
|
||||
unsigned char *buf;
|
||||
MemFile *compare, *current;
|
||||
@@ -325,7 +325,7 @@ static WriteData *writedata_new(WriteWrap *ww)
|
||||
{
|
||||
WriteData *wd = MEM_callocN(sizeof(*wd), "writedata");
|
||||
|
||||
wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, NULL);
|
||||
wd->sdna = DNA_sdna_current_get();
|
||||
|
||||
wd->ww = ww;
|
||||
|
||||
@@ -357,8 +357,6 @@ static void writedata_do_write(WriteData *wd, const void *mem, int memlen)
|
||||
|
||||
static void writedata_free(WriteData *wd)
|
||||
{
|
||||
DNA_sdna_free(wd->sdna);
|
||||
|
||||
MEM_freeN(wd->buf);
|
||||
MEM_freeN(wd);
|
||||
}
|
||||
|
||||
@@ -80,6 +80,12 @@ struct SDNA *DNA_sdna_from_data(
|
||||
const char **r_error_message);
|
||||
void DNA_sdna_free(struct SDNA *sdna);
|
||||
|
||||
/* Access for current Blender versions SDNA*/
|
||||
void DNA_sdna_current_init(void);
|
||||
/* borrowed reference */
|
||||
const struct SDNA *DNA_sdna_current_get(void);
|
||||
void DNA_sdna_current_free(void);
|
||||
|
||||
int DNA_struct_find_nr_ex(const struct SDNA *sdna, const char *str, unsigned int *index_last);
|
||||
int DNA_struct_find_nr(const struct SDNA *sdna, const char *str);
|
||||
void DNA_struct_switch_endian(const struct SDNA *oldsdna, int oldSDNAnr, char *data);
|
||||
|
||||
@@ -605,6 +605,30 @@ SDNA *DNA_sdna_from_data(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Using globals is acceptable here, the data is read-only and only changes between Blender versions.
|
||||
*
|
||||
* So it is safe to create once and reuse.
|
||||
*/
|
||||
static SDNA *g_sdna = NULL;
|
||||
|
||||
void DNA_sdna_current_init(void)
|
||||
{
|
||||
g_sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, NULL);
|
||||
}
|
||||
|
||||
const struct SDNA *DNA_sdna_current_get(void)
|
||||
{
|
||||
BLI_assert(g_sdna != NULL);
|
||||
return g_sdna;
|
||||
}
|
||||
|
||||
void DNA_sdna_current_free(void)
|
||||
{
|
||||
DNA_sdna_free(g_sdna);
|
||||
g_sdna = NULL;
|
||||
}
|
||||
|
||||
/* ******************** END READ DNA ********************** */
|
||||
|
||||
/* ******************* HANDLE DNA ***************** */
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_genfile.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
#include "DNA_windowmanager_types.h"
|
||||
@@ -584,6 +585,8 @@ void WM_exit_ext(bContext *C, const bool do_python)
|
||||
|
||||
GHOST_DisposeSystemPaths();
|
||||
|
||||
DNA_sdna_current_free();
|
||||
|
||||
BLI_threadapi_exit();
|
||||
|
||||
BKE_blender_atexit();
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_genfile.h"
|
||||
|
||||
#include "BLI_args.h"
|
||||
#include "BLI_threads.h"
|
||||
#include "BLI_utildefines.h"
|
||||
@@ -350,6 +352,8 @@ int main(
|
||||
|
||||
BLI_threadapi_init();
|
||||
|
||||
DNA_sdna_current_init();
|
||||
|
||||
BKE_blender_globals_init(); /* blender.c */
|
||||
|
||||
IMB_init();
|
||||
|
||||
Reference in New Issue
Block a user