diff options
author | Bastien Montagne <bastien@blender.org> | 2020-07-03 11:40:42 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2020-07-03 13:56:21 +0300 |
commit | 5dda6cefb64e4ff1205cbeda96010fd9bb0f057c (patch) | |
tree | 487ed152d7e27af48fd58d55cd869715c4892102 /source/blender/blenkernel/intern | |
parent | a06d95987e3e2bff131633636f7c7e25e0528a3b (diff) |
Add key structure and hashing utils for ID caches.
Part of D8183, refactoring how we preserve caches across undo steps in
readfile code.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/idtype.c | 17 |
1 files changed, 17 insertions, 0 deletions
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) |