[Bf-blender-cvs] [5dda6cefb64] master: Add key structure and hashing utils for ID caches.

Bastien Montagne noreply at git.blender.org
Fri Jul 3 12:56:35 CEST 2020


Commit: 5dda6cefb64e4ff1205cbeda96010fd9bb0f057c
Author: Bastien Montagne
Date:   Fri Jul 3 10:40:42 2020 +0200
Branches: master
https://developer.blender.org/rB5dda6cefb64e4ff1205cbeda96010fd9bb0f057c

Add key structure and hashing utils for ID caches.

Part of D8183, refactoring how we preserve caches across undo steps in
readfile code.

===================================================================

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/intern/idtype.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index b6dfadd3b2a..56e788ccfe8 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -46,6 +46,19 @@ enum {
   IDTYPE_FLAGS_NO_MAKELOCAL = 1 << 2,
 };
 
+typedef struct IDCacheKey {
+  /* The session uuid of the ID owning the cached data. */
+  unsigned int id_session_uuid;
+  /* Value uniquely indentifying the cache whithin its ID.
+   * Typically the offset of its member in the data-block struct, but can be anything. */
+  size_t offset_in_ID;
+  /* Actual address of the cached data to save and restore. */
+  void *cache_v;
+} IDCacheKey;
+
+uint BKE_idtype_cache_key_hash(const void *key_v);
+bool BKE_idtype_cache_key_cmp(const void *key_a_v, const void *key_b_v);
+
 /* ********** Prototypes for IDTypeInfo callbacks. ********** */
 
 typedef void (*IDTypeInitDataFunction)(struct ID *id);
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index fcd3bc9c5b4..2684e964eb1 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -28,6 +28,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_ghash.h"
 #include "BLI_utildefines.h"
 
 #include "CLG_log.h"
@@ -42,6 +43,22 @@
 
 // static CLG_LogRef LOG = {"bke.idtype"};
 
+uint BKE_idtype_cache_key_hash(const void *key_v)
+{
+  const IDCacheKey *key = key_v;
+  size_t hash = BLI_ghashutil_uinthash(key->id_session_uuid);
+  hash = BLI_ghashutil_combine_hash(hash, BLI_ghashutil_uinthash((uint)key->offset_in_ID));
+  return (uint)BLI_ghashutil_combine_hash(hash, BLI_ghashutil_ptrhash(key->cache_v));
+}
+
+bool BKE_idtype_cache_key_cmp(const void *key_a_v, const void *key_b_v)
+{
+  const IDCacheKey *key_a = key_a_v;
+  const IDCacheKey *key_b = key_b_v;
+  return (key_a->id_session_uuid != key_b->id_session_uuid) ||
+         (key_a->offset_in_ID != key_b->offset_in_ID) || (key_a->cache_v != key_b->cache_v);
+}
+
 static IDTypeInfo *id_types[MAX_LIBARRAY] = {NULL};
 
 static void id_type_init(void)



More information about the Bf-blender-cvs mailing list