[Bf-blender-cvs] [180ec7fca31] undo-write: Undo write optimizations: Final cleanups and some comments.
Bastien Montagne
noreply at git.blender.org
Wed Jun 3 12:07:12 CEST 2020
Commit: 180ec7fca31ea792e786bdbb961e474d9c0347b6
Author: Bastien Montagne
Date: Wed Jun 3 12:06:36 2020 +0200
Branches: undo-write
https://developer.blender.org/rB180ec7fca31ea792e786bdbb961e474d9c0347b6
Undo write optimizations: Final cleanups and some comments.
===================================================================
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/undofile.c
M source/blender/blenloader/intern/writefile.c
===================================================================
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 16a86ebb306..d3c391a1595 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -240,7 +240,7 @@
#define USE_GHASH_RESTORE_POINTER
/* Define this to have verbose debug prints. */
-#define USE_DEBUG_PRINT
+//#define USE_DEBUG_PRINT
#ifdef USE_DEBUG_PRINT
# define DEBUG_PRINTF(...) printf(__VA_ARGS__)
diff --git a/source/blender/blenloader/intern/undofile.c b/source/blender/blenloader/intern/undofile.c
index 984bb02413a..28b37c4a737 100644
--- a/source/blender/blenloader/intern/undofile.c
+++ b/source/blender/blenloader/intern/undofile.c
@@ -110,6 +110,11 @@ void BLO_memfile_write_init(MemFileWriteData *mem_data,
mem_data->reference_memfile = reference_memfile;
mem_data->reference_current_chunk = reference_memfile ? reference_memfile->chunks.first : NULL;
+ /* If we have a reference memfile, we generate a mapping between the session_uuid's of the IDs
+ * stored in that previous undo step, and its first matching memchunk.
+ * This will allow us to easily find the existing undo memory storage of IDs even when some
+ * re-ordering in current Main data-base broke the order matching with the memchunks from
+ * previous step. */
if (reference_memfile != NULL) {
mem_data->id_session_uuid_mapping = BLI_ghash_new(
BLI_ghashutil_inthash_p_simple, BLI_ghashutil_intcmp, __func__);
@@ -159,7 +164,6 @@ void BLO_memfile_chunk_add(MemFileWriteData *mem_data, const char *buf, uint siz
MemFileChunk *compchunk = *compchunk_step;
if (compchunk->size == curchunk->size) {
if (memcmp(compchunk->buf, buf, size) == 0) {
- printf("\t\tIdentical…\n");
curchunk->buf = compchunk->buf;
curchunk->is_identical = true;
compchunk->is_identical_future = true;
@@ -170,7 +174,6 @@ void BLO_memfile_chunk_add(MemFileWriteData *mem_data, const char *buf, uint siz
/* not equal... */
if (curchunk->buf == NULL) {
- printf("\t\tDifferent!\n");
char *buf_new = MEM_mallocN(size, "Chunk buffer");
memcpy(buf_new, buf, size);
curchunk->buf = buf_new;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 365a0cd7dcc..f7dabcd71cc 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -505,28 +505,22 @@ static bool mywrite_end(WriteData *wd)
static void mywrite_id_begin(WriteData *wd, ID *id)
{
if (wd->use_memfile) {
- printf("START writing id %s\n", id->name);
wd->mem.current_id_session_uuid = id->session_uuid;
+
+ /* If current next memchunk does not match the ID we are about to write, try to find the
+ * correct memchunk in the mapping using ID's session_uuid. */
if (wd->mem.id_session_uuid_mapping != NULL &&
(wd->mem.reference_current_chunk == NULL ||
wd->mem.reference_current_chunk->id_session_uuid != id->session_uuid)) {
void *ref = BLI_ghash_lookup(wd->mem.id_session_uuid_mapping,
POINTER_FROM_UINT(id->session_uuid));
if (ref != NULL) {
- printf("\tFound existing memchunk, had to search\n");
wd->mem.reference_current_chunk = ref;
}
- else {
- printf("\tNo existing memchunk found, assuming this is a new ID\n");
- }
- }
- else if (wd->mem.reference_current_chunk != NULL &&
- wd->mem.reference_current_chunk->id_session_uuid == id->session_uuid) {
- printf("\tFound existing memchunk, was current one\n");
- }
- else {
- printf("\tFound no matching existing memchunk, trying with current one anyway\n");
+ /* Else, no existing memchunk found, i.e. this is supposed to be a new ID. */
}
+ /* Otherwise, we try with the current memchunk in any case, whether it is matching current
+ * ID's session_uuid or not. */
}
}
@@ -542,7 +536,6 @@ static void mywrite_id_end(WriteData *wd, ID *id)
* specific ID changed or not. */
mywrite_flush(wd);
wd->mem.current_id_session_uuid = MAIN_ID_SESSION_UUID_UNSET;
- printf("END writing id %s\n", id->name);
}
}
More information about the Bf-blender-cvs
mailing list