util/disk_cache: use a helper to compute cache keys

This will allow to hash additional data into the cache keys or even
change the hashing algorithm easily, should we decide to do so.

v2: don't try to compute key (and crash) if cache is disabled

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Grazvydas Ignotas
2017-03-16 01:09:27 +02:00
committed by Timothy Arceri
parent 021c87fa24
commit 529a767041
7 changed files with 51 additions and 25 deletions
+14
View File
@@ -178,6 +178,13 @@ disk_cache_put_key(struct disk_cache *cache, const cache_key key);
bool
disk_cache_has_key(struct disk_cache *cache, const cache_key key);
/**
* Compute the name \key from \data of given \size.
*/
void
disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size,
cache_key key);
#else
static inline struct disk_cache *
@@ -222,6 +229,13 @@ disk_cache_has_key(struct disk_cache *cache, const cache_key key)
return false;
}
void
disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size,
const cache_key key)
{
return;
}
#endif /* ENABLE_SHADER_CACHE */
#ifdef __cplusplus