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
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/blender/makesdna
parent4db1db327a0613abee950ffe12b013afdec2c111 (diff)
writefile: reuse SDNA between writes
Avoids decoding the SDNA string every undo step.
Diffstat (limited to 'source/blender/makesdna')
-rw-r--r--source/blender/makesdna/DNA_genfile.h6
-rw-r--r--source/blender/makesdna/intern/dna_genfile.c24
2 files changed, 30 insertions, 0 deletions
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 ***************** */