From cbd4a79c6d8bf479fc0914df29f8d367b232bb1a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 14 Apr 2018 12:33:19 +0200 Subject: Undo: refactor memfile writing - Move static undo variable into 'WriteData', 'memfile_chunk_add' used arguments in a confusing way, sometimes to set/clear static var. - Replace checks for 'wd->current' with 'wd->use_memfile' move memfile vars into 'wd->mem' struct. --- source/blender/blenloader/intern/undofile.c | 30 ++++++++++------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'source/blender/blenloader/intern/undofile.c') diff --git a/source/blender/blenloader/intern/undofile.c b/source/blender/blenloader/intern/undofile.c index f6584ecf25f..7133dee0e82 100644 --- a/source/blender/blenloader/intern/undofile.c +++ b/source/blender/blenloader/intern/undofile.c @@ -96,36 +96,26 @@ void BLO_memfile_merge(MemFile *first, MemFile *second) BLO_memfile_free(first); } -void memfile_chunk_add(MemFile *compare, MemFile *current, const char *buf, unsigned int size) +void memfile_chunk_add( + MemFile *memfile, const char *buf, unsigned int size, + MemFileChunk **compchunk_step) { - static MemFileChunk *compchunk = NULL; - MemFileChunk *curchunk; - - /* this function inits when compare != NULL or when current == NULL */ - if (compare) { - compchunk = compare->chunks.first; - return; - } - if (current == NULL) { - compchunk = NULL; - return; - } - - curchunk = MEM_mallocN(sizeof(MemFileChunk), "MemFileChunk"); + MemFileChunk *curchunk = MEM_mallocN(sizeof(MemFileChunk), "MemFileChunk"); curchunk->size = size; curchunk->buf = NULL; curchunk->is_identical = false; - BLI_addtail(¤t->chunks, curchunk); - + BLI_addtail(&memfile->chunks, curchunk); + /* we compare compchunk with buf */ - if (compchunk) { + if (*compchunk_step != NULL) { + MemFileChunk *compchunk = *compchunk_step; if (compchunk->size == curchunk->size) { if (memcmp(compchunk->buf, buf, size) == 0) { curchunk->buf = compchunk->buf; curchunk->is_identical = true; } } - compchunk = compchunk->next; + *compchunk_step = compchunk->next; } /* not equal... */ @@ -133,7 +123,7 @@ void memfile_chunk_add(MemFile *compare, MemFile *current, const char *buf, unsi char *buf_new = MEM_mallocN(size, "Chunk buffer"); memcpy(buf_new, buf, size); curchunk->buf = buf_new; - current->size += size; + memfile->size += size; } } -- cgit v1.2.3