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->filedes = -1;
|
||||||
fd->gzfiledes = NULL;
|
fd->gzfiledes = NULL;
|
||||||
|
|
||||||
/* XXX, this doesn't need to be done all the time,
|
fd->memsdna = DNA_sdna_current_get();
|
||||||
* 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->datamap = oldnewmap_new();
|
fd->datamap = oldnewmap_new();
|
||||||
fd->globmap = oldnewmap_new();
|
fd->globmap = oldnewmap_new();
|
||||||
fd->libmap = oldnewmap_new();
|
fd->libmap = oldnewmap_new();
|
||||||
@@ -1280,9 +1276,7 @@ void blo_freefiledata(FileData *fd)
|
|||||||
|
|
||||||
// Free all BHeadN data blocks
|
// Free all BHeadN data blocks
|
||||||
BLI_freelistN(&fd->listbase);
|
BLI_freelistN(&fd->listbase);
|
||||||
|
|
||||||
if (fd->memsdna)
|
|
||||||
DNA_sdna_free(fd->memsdna);
|
|
||||||
if (fd->filesdna)
|
if (fd->filesdna)
|
||||||
DNA_sdna_free(fd->filesdna);
|
DNA_sdna_free(fd->filesdna);
|
||||||
if (fd->compflags)
|
if (fd->compflags)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ typedef struct FileData {
|
|||||||
|
|
||||||
// general reading variables
|
// general reading variables
|
||||||
struct SDNA *filesdna;
|
struct SDNA *filesdna;
|
||||||
struct SDNA *memsdna;
|
const struct SDNA *memsdna;
|
||||||
char *compflags; /* array of eSDNA_StructCompare */
|
char *compflags; /* array of eSDNA_StructCompare */
|
||||||
|
|
||||||
int fileversion;
|
int fileversion;
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ static void ww_handle_init(eWriteWrapType ww_type, WriteWrap *r_ww)
|
|||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct SDNA *sdna;
|
const struct SDNA *sdna;
|
||||||
|
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
MemFile *compare, *current;
|
MemFile *compare, *current;
|
||||||
@@ -325,7 +325,7 @@ static WriteData *writedata_new(WriteWrap *ww)
|
|||||||
{
|
{
|
||||||
WriteData *wd = MEM_callocN(sizeof(*wd), "writedata");
|
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;
|
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)
|
static void writedata_free(WriteData *wd)
|
||||||
{
|
{
|
||||||
DNA_sdna_free(wd->sdna);
|
|
||||||
|
|
||||||
MEM_freeN(wd->buf);
|
MEM_freeN(wd->buf);
|
||||||
MEM_freeN(wd);
|
MEM_freeN(wd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,12 @@ struct SDNA *DNA_sdna_from_data(
|
|||||||
const char **r_error_message);
|
const char **r_error_message);
|
||||||
void DNA_sdna_free(struct SDNA *sdna);
|
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_ex(const struct SDNA *sdna, const char *str, unsigned int *index_last);
|
||||||
int DNA_struct_find_nr(const struct SDNA *sdna, const char *str);
|
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);
|
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 ********************** */
|
/* ******************** END READ DNA ********************** */
|
||||||
|
|
||||||
/* ******************* HANDLE DNA ***************** */
|
/* ******************* HANDLE DNA ***************** */
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
|
#include "DNA_genfile.h"
|
||||||
#include "DNA_scene_types.h"
|
#include "DNA_scene_types.h"
|
||||||
#include "DNA_userdef_types.h"
|
#include "DNA_userdef_types.h"
|
||||||
#include "DNA_windowmanager_types.h"
|
#include "DNA_windowmanager_types.h"
|
||||||
@@ -584,6 +585,8 @@ void WM_exit_ext(bContext *C, const bool do_python)
|
|||||||
|
|
||||||
GHOST_DisposeSystemPaths();
|
GHOST_DisposeSystemPaths();
|
||||||
|
|
||||||
|
DNA_sdna_current_free();
|
||||||
|
|
||||||
BLI_threadapi_exit();
|
BLI_threadapi_exit();
|
||||||
|
|
||||||
BKE_blender_atexit();
|
BKE_blender_atexit();
|
||||||
|
|||||||
@@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
|
#include "DNA_genfile.h"
|
||||||
|
|
||||||
#include "BLI_args.h"
|
#include "BLI_args.h"
|
||||||
#include "BLI_threads.h"
|
#include "BLI_threads.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
@@ -350,6 +352,8 @@ int main(
|
|||||||
|
|
||||||
BLI_threadapi_init();
|
BLI_threadapi_init();
|
||||||
|
|
||||||
|
DNA_sdna_current_init();
|
||||||
|
|
||||||
BKE_blender_globals_init(); /* blender.c */
|
BKE_blender_globals_init(); /* blender.c */
|
||||||
|
|
||||||
IMB_init();
|
IMB_init();
|
||||||
|
|||||||
Reference in New Issue
Block a user