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-06 15:23:50 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-07-06 16:07:37 +0300
commita0793765ef229b0d93bb9216b57faeb5940c5986 (patch)
tree986febb1a84980d9ae2bda092901859dd5385fe4 /source/blender/makesdna
parent94e84f5be41de0f5b222f091e97f9fd0ad959460 (diff)
writefile: avoid adding SDNA to every undo step
Since SDNA was allocated for each undo step, the new address meant it was considered different and included again. Add an option not to duplicate the DNA string when calling DNA_sdna_from_data, as well as avoiding a redundant copy, it writes the same address each time.
Diffstat (limited to 'source/blender/makesdna')
-rw-r--r--source/blender/makesdna/DNA_genfile.h4
-rw-r--r--source/blender/makesdna/DNA_sdna_types.h3
-rw-r--r--source/blender/makesdna/intern/dna_genfile.c20
3 files changed, 21 insertions, 6 deletions
diff --git a/source/blender/makesdna/DNA_genfile.h b/source/blender/makesdna/DNA_genfile.h
index d62369803d6..77877f7bada 100644
--- a/source/blender/makesdna/DNA_genfile.h
+++ b/source/blender/makesdna/DNA_genfile.h
@@ -74,7 +74,9 @@ enum eSDNA_StructCompare {
SDNA_CMP_NOT_EQUAL = 2,
};
-struct SDNA *DNA_sdna_from_data(const void *data, const int datalen, bool do_endian_swap);
+struct SDNA *DNA_sdna_from_data(
+ const void *data, const int datalen,
+ bool do_endian_swap, bool data_alloc);
void DNA_sdna_free(struct SDNA *sdna);
int DNA_struct_find_nr(struct SDNA *sdna, const char *str);
diff --git a/source/blender/makesdna/DNA_sdna_types.h b/source/blender/makesdna/DNA_sdna_types.h
index cb7a371c7c5..791aca77558 100644
--- a/source/blender/makesdna/DNA_sdna_types.h
+++ b/source/blender/makesdna/DNA_sdna_types.h
@@ -35,8 +35,9 @@
#
#
typedef struct SDNA {
- char *data; /* full copy of 'encoded' data */
+ const char *data; /* full copy of 'encoded' data */
int datalen; /* length of data */
+ bool data_alloc;
int nr_names; /* total number of struct members */
const char **names; /* struct member names */
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c
index 99ab29fbdcc..9135d7bab7d 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -196,7 +196,10 @@ int DNA_elem_array_size(const char *str)
void DNA_sdna_free(SDNA *sdna)
{
- MEM_freeN(sdna->data);
+ if (sdna->data_alloc) {
+ MEM_freeN((void *)sdna->data);
+ }
+
MEM_freeN((void *)sdna->names);
MEM_freeN(sdna->types);
MEM_freeN(sdna->structs);
@@ -549,15 +552,24 @@ static void init_structDNA(SDNA *sdna, bool do_endian_swap)
/**
* Constructs and returns a decoded SDNA structure from the given encoded SDNA data block.
*/
-SDNA *DNA_sdna_from_data(const void *data, const int datalen, bool do_endian_swap)
+SDNA *DNA_sdna_from_data(
+ const void *data, const int datalen,
+ bool do_endian_swap, bool data_alloc)
{
SDNA *sdna = MEM_mallocN(sizeof(*sdna), "sdna");
sdna->lastfind = 0;
sdna->datalen = datalen;
- sdna->data = MEM_mallocN(datalen, "sdna_data");
- memcpy(sdna->data, data, datalen);
+ if (data_alloc) {
+ char *data_copy = MEM_mallocN(datalen, "sdna_data");
+ memcpy(data_copy, data, datalen);
+ sdna->data = data_copy;
+ }
+ else {
+ sdna->data = data;
+ }
+ sdna->data_alloc = data_alloc;
init_structDNA(sdna, do_endian_swap);