Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-07-12 05:53:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-07-12 06:03:04 +0300
commit0708b9aba8f7da87c4cf97b96c0bc9229fa9689c (patch)
tree63588657c286dfeb0d0ce99b64c16dbfbbd93213 /source
parent4db1db327a0613abee950ffe12b013afdec2c111 (diff)
writefile: reuse SDNA between writes
Avoids decoding the SDNA string every undo step.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenloader/intern/readfile.c14
-rw-r--r--source/blender/blenloader/intern/readfile.h2
-rw-r--r--source/blender/blenloader/intern/writefile.c6
-rw-r--r--source/blender/makesdna/DNA_genfile.h6
-rw-r--r--source/blender/makesdna/intern/dna_genfile.c24
-rw-r--r--source/blender/windowmanager/intern/wm_init_exit.c3
-rw-r--r--source/creator/creator.c4
7 files changed, 44 insertions, 15 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index eeb8a5d8dbd..059dce2459e 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -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)
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 42728fd406f..b054cd0031d 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -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;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index f898eea566d..88f1c4d5e4a 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -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);
}
diff --git a/source/blender/makesdna/DNA_genfile.h b/source/blender/makesdna/DNA_genfile.h
index 27a3ff8f8cb..bc127ac2c82 100644
--- a/source/blender/makesdna/DNA_genfile.h
+++ b/source/blender/makesdna/DNA_genfile.h
@@ -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);
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c
index f1d48c07de1..1e3c91d5ddc 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -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 ***************** */
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 9d1083bbf63..3022d865460 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -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();
diff --git a/source/creator/creator.c b/source/creator/creator.c
index e2761c9ef38..289e68f6276 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -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();