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>2018-04-03 17:46:11 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-04-03 18:03:33 +0300
commit75de21f0722c3a7d674c208cf6af95044637828f (patch)
treee7c01d6cc415def033f80bc586afc1536fb2a6cc /source/blender/blenkernel/intern/undo_system.c
parent53f068454e8c774ef68997f3b8afb5da9417b03c (diff)
Undo System: id-map avoid duplicate add/lookup
Add versions of add/lookup that check the previous item.
Diffstat (limited to 'source/blender/blenkernel/intern/undo_system.c')
-rw-r--r--source/blender/blenkernel/intern/undo_system.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index bb4c0b1130e..d478be7db06 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -776,6 +776,7 @@ void BKE_undosys_ID_map_add(UndoIDPtrMap *map, ID *id)
map->pmap[len_src].index = len_src;
map->len = len_dst;
+ /* TODO(campbell): use binary search result and memmove instread of full-sort. */
qsort(map->pmap, map->len, sizeof(*map->pmap), BLI_sortutil_cmp_ptr);
}
@@ -792,4 +793,26 @@ ID *BKE_undosys_ID_map_lookup(const UndoIDPtrMap *map, const ID *id_src)
return id_dst;
}
+void BKE_undosys_ID_map_add_with_prev(UndoIDPtrMap *map, ID *id, ID **id_prev)
+{
+ if (id == *id_prev) {
+ return;
+ }
+ *id_prev = id;
+ BKE_undosys_ID_map_add(map, id);
+}
+
+ID *BKE_undosys_ID_map_lookup_with_prev(const UndoIDPtrMap *map, ID *id_src, ID *id_prev_match[2])
+{
+ if (id_src == id_prev_match[0]) {
+ return id_prev_match[1];
+ }
+ else {
+ ID *id_dst = BKE_undosys_ID_map_lookup(map, id_src);
+ id_prev_match[0] = id_src;
+ id_prev_match[1] = id_dst;
+ return id_dst;
+ }
+}
+
/** \} */