[Bf-blender-cvs] [2842949] asset-experiments: Add uuids ghash to filelist's cache.
Bastien Montagne
noreply at git.blender.org
Mon Apr 13 21:55:05 CEST 2015
Commit: 2842949e13dbb8aba116d48d984fadd86bfa4392
Author: Bastien Montagne
Date: Mon Apr 13 21:54:37 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rB2842949e13dbb8aba116d48d984fadd86bfa4392
Add uuids ghash to filelist's cache.
===================================================================
M source/blender/editors/space_file/filelist.c
M source/blender/makesdna/DNA_space_types.h
===================================================================
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 6c827f4..f675c96 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -237,6 +237,9 @@ typedef struct FileListEntryCache {
int misc_entries_indices[FILELIST_ENTRYCACHESIZE];
GHash *misc_entries;
+ /* Allows to quickly get a cached entry from its UUID. */
+ GHash *uuids;
+
/* Previews handling. */
TaskPool *previews_pool;
ThreadQueue *previews_todo;
@@ -1167,6 +1170,10 @@ static void filelist_cache_init(FileListEntryCache *cache)
cache->misc_entries = BLI_ghash_ptr_new_ex(__func__, FILELIST_ENTRYCACHESIZE);
fill_vn_i(cache->misc_entries_indices, ARRAY_SIZE(cache->misc_entries_indices), -1);
cache->misc_cursor = 0;
+
+ /* XXX This assumes uint is 32 bits and uuid is 128 bits (char[16]), be careful! */
+ cache->uuids = BLI_ghash_new_ex(BLI_ghashutil_uinthash_v4, BLI_ghashutil_uinthash_v4_cmp,
+ __func__, FILELIST_ENTRYCACHESIZE * 2);
}
static void filelist_cache_free(FileListEntryCache *cache)
@@ -1178,6 +1185,11 @@ static void filelist_cache_free(FileListEntryCache *cache)
BLI_ghash_free(cache->misc_entries, NULL, NULL);
cache->misc_entries = NULL;
}
+
+ if (cache->uuids) {
+ BLI_ghash_free(cache->uuids, NULL, NULL);
+ cache->uuids = NULL;
+ }
}
static void filelist_cache_clear(FileListEntryCache *cache)
@@ -1190,6 +1202,10 @@ static void filelist_cache_clear(FileListEntryCache *cache)
if (cache->misc_entries) {
BLI_ghash_clear_ex(cache->misc_entries, NULL, NULL, FILELIST_ENTRYCACHESIZE);
}
+
+ if (cache->uuids) {
+ BLI_ghash_clear_ex(cache->uuids, NULL, NULL, FILELIST_ENTRYCACHESIZE * 2);
+ }
}
FileList *filelist_new(short type)
@@ -1424,9 +1440,12 @@ static FileDirEntry *filelist_file_ex(struct FileList *filelist, const int index
ret = filelist_file_create_entry(filelist, index);
old_index = cache->misc_entries_indices[cache->misc_cursor];
if ((old = BLI_ghash_popkey(cache->misc_entries, SET_INT_IN_POINTER(old_index), NULL))) {
+ BLI_ghash_remove(cache->uuids, old->uuid, NULL, NULL);
filelist_file_release_entry(filelist, old);
}
BLI_ghash_insert(cache->misc_entries, SET_INT_IN_POINTER(index), ret);
+ BLI_ghash_insert(cache->uuids, ret->uuid, ret);
+
cache->misc_entries_indices[cache->misc_cursor] = index;
cache->misc_cursor = (cache->misc_cursor + 1) % FILELIST_ENTRYCACHESIZE;
@@ -1453,7 +1472,7 @@ int filelist_file_findpath(struct FileList *filelist, const char *filename)
}
/* XXX TODO Cache could probably use a ghash on paths too? Not really urgent though.
- * In fact, we may get rid of this func in the end (only used to find again renamed entry afaik). */
+ * This is only used to find again renamed entry, annoying but looks hairy to get rid of it currently. */
for (fidx = 0; fidx < filelist->filelist.nbr_entries_filtered; fidx++) {
FileListInternEntry *entry = filelist->filelist_intern.filtered[fidx];
@@ -1467,18 +1486,25 @@ int filelist_file_findpath(struct FileList *filelist, const char *filename)
FileDirEntry *filelist_entry_find_uuid(struct FileList *filelist, const char uuid[ASSET_UUID_LENGTH])
{
- int fidx;
-
if (filelist->filelist.nbr_entries_filtered < 0) {
return NULL;
}
- /* XXX TODO Cache could probably use a ghash on uuids too? Not really urgent though. */
+ if (filelist->filelist_cache.uuids) {
+ FileDirEntry *entry = BLI_ghash_lookup(filelist->filelist_cache.uuids, uuid);
+ if (entry) {
+ return entry;
+ }
+ }
- for (fidx = 0; fidx < filelist->filelist.nbr_entries_filtered; fidx++) {
- FileListInternEntry *entry = filelist->filelist_intern.filtered[fidx];
- if (memcmp(entry->uuid, uuid, sizeof(entry->uuid)) == 0) {
- return filelist_file(filelist, fidx);
+ {
+ int fidx;
+
+ for (fidx = 0; fidx < filelist->filelist.nbr_entries_filtered; fidx++) {
+ FileListInternEntry *entry = filelist->filelist_intern.filtered[fidx];
+ if (memcmp(entry->uuid, uuid, sizeof(entry->uuid)) == 0) {
+ return filelist_file(filelist, fidx);
+ }
}
}
@@ -1494,7 +1520,9 @@ static bool filelist_file_cache_block_create(struct FileList *filelist, const in
int i, idx;
for (i = 0, idx = start_index; i < size; i++, idx++, cursor++) {
- cache->block_entries[cursor] = filelist_file_create_entry(filelist, idx);
+ FileDirEntry *entry = filelist_file_create_entry(filelist, idx);
+ cache->block_entries[cursor] = entry;
+ BLI_ghash_insert(cache->uuids, entry->uuid, entry);
}
return true;
}
@@ -1510,8 +1538,10 @@ static void filelist_file_cache_block_release(struct FileList *filelist, const i
int i;
for (i = 0; i < size; i++, cursor++) {
+ FileDirEntry *entry = cache->block_entries[cursor];
// printf("%s: release cacheidx %d (%%p %%s)\n", __func__, cursor/*, cache->block_entries[cursor], cache->block_entries[cursor]->relpath*/);
- filelist_file_release_entry(filelist, cache->block_entries[cursor]);
+ BLI_ghash_remove(cache->uuids, entry->uuid, NULL, NULL);
+ filelist_file_release_entry(filelist, entry);
#ifndef NDEBUG
cache->block_entries[cursor] = NULL;
#endif
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 665a734..425eb69 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -743,7 +743,10 @@ typedef enum eDirEntry_SelectFlag {
/* ***** Related to file browser, but never saved in DNA, only here to help with RNA. ***** */
-/* For RNA only, used to communicate with asset engines outside of 'import' context. */
+/* Be careful, we assume uuid is 128 bits (char[16]) in a few places, like uuids ghash in filecache of filebrowser. */
+#define ASSET_UUID_LENGTH 16
+
+/* Used to communicate with asset engines outside of 'import' context. */
typedef struct AssetUUID {
char uuid_asset[16]; /* ASSET_UUID_LENGTH */
char uuid_variant[16]; /* ASSET_UUID_LENGTH */
@@ -852,8 +855,6 @@ typedef struct FileDirEntryArr {
char root[1024]; /* FILE_MAX */
} FileDirEntryArr;
-#define ASSET_UUID_LENGTH 16
-
enum {
ASSET_STATUS_LOCAL = 1 << 0, /* If active uuid is available localy/immediately. */
ASSET_STATUS_LATEST = 1 << 1, /* If active uuid is latest available version. */
More information about the Bf-blender-cvs
mailing list