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.
This commit is contained in:
2016-07-06 22:23:50 +10:00
parent 94e84f5be4
commit a0793765ef
6 changed files with 36 additions and 11 deletions

View File

@@ -918,7 +918,7 @@ static int read_file_dna(FileData *fd)
if (bhead->code == DNA1) {
const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0;
fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap);
fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap, true);
if (fd->filesdna) {
fd->compflags = DNA_struct_get_compareflags(fd->filesdna, fd->memsdna);
/* used to retrieve ID names from (bhead+1) */
@@ -1078,7 +1078,7 @@ static FileData *filedata_new(void)
* 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);
fd->memsdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false);
fd->datamap = oldnewmap_new();
fd->globmap = oldnewmap_new();

View File

@@ -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);
wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false);
wd->ww = ww;
@@ -4013,6 +4013,10 @@ static bool write_file_handle(
write_thumb(wd, thumb);
write_global(wd, write_flags, mainvar);
/* The windowmanager and screen often change,
* avoid thumbnail detecting changes because of this. */
mywrite(wd, MYWRITE_FLUSH, 0);
write_windowmanagers(wd, &mainvar->wm);
write_screens(wd, &mainvar->screen);
write_movieclips(wd, &mainvar->movieclip);
@@ -4046,11 +4050,17 @@ static bool write_file_handle(
write_linestyles(wd, &mainvar->linestyle);
write_libraries(wd, mainvar->next);
/* So changes above don't cause a 'DNA1' to be detected as changed on undo. */
mywrite(wd, MYWRITE_FLUSH, 0);
if (write_flags & G_FILE_USERPREFS) {
write_userdef(wd);
}
/* dna as last, because (to be implemented) test for which structs are written */
/* Write DNA last, because (to be implemented) test for which structs are written.
*
* Note that we *borrow* the pointer to 'DNAstr',
* so writing each time uses the same address and doesn't cause unnecessary undo overhead. */
writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data);
#ifdef USE_NODE_COMPAT_CUSTOMNODES