[Bf-blender-cvs] [f616871] asset-experiments: Selection/UUIDs handling enhancements:

Bastien Montagne noreply at git.blender.org
Tue Jun 16 17:33:30 CEST 2015


Commit: f616871e62b52cfdbed7d75fee4109e99984a598
Author: Bastien Montagne
Date:   Tue Jun 16 16:19:06 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rBf616871e62b52cfdbed7d75fee4109e99984a598

Selection/UUIDs handling enhancements:

* Do not systematically clear selection_state's uuids GHash when updating filelist
  during listing process - uuids used here should remain valid.
  Allows to not lose selections during listing background job!
* Use new BLI_ghash_lookup_p to handle selection state setting, symbolic optimization but...

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

M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h

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

diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 24406aa..0a67a2d 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1207,7 +1207,7 @@ FileList *filelist_new(short type)
 	return p;
 }
 
-void filelist_clear(struct FileList *filelist)
+void filelist_clear_ex(struct FileList *filelist, const bool do_cache, const bool do_selection)
 {
 	if (!filelist) {
 		return;
@@ -1215,17 +1215,24 @@ void filelist_clear(struct FileList *filelist)
 
 	filelist_filter_clear(filelist);
 
-	filelist_cache_clear(&filelist->filelist_cache, filelist->filelist_cache.size);
+	if (do_cache) {
+		filelist_cache_clear(&filelist->filelist_cache, filelist->filelist_cache.size);
+	}
 
 	filelist_intern_free(&filelist->filelist_intern);
 
 	filelist_direntryarr_free(&filelist->filelist);
 
-	if (filelist->selection_state) {
+	if (do_selection && filelist->selection_state) {
 		BLI_ghash_clear(filelist->selection_state, MEM_freeN, NULL);
 	}
 }
 
+void filelist_clear(struct FileList *filelist)
+{
+	filelist_clear_ex(filelist, true, true);
+}
+
 void filelist_free(struct FileList *filelist)
 {
 	if (!filelist) {
@@ -1233,8 +1240,8 @@ void filelist_free(struct FileList *filelist)
 		return;
 	}
 	
-	filelist_clear(filelist);
-	filelist_cache_free(&filelist->filelist_cache);  /* XXX TODO stupid! */
+	filelist_clear_ex(filelist, false, false);  /* No need to clear cache & selection_state, we free them anyway. */
+	filelist_cache_free(&filelist->filelist_cache);
 
 	if (filelist->selection_state) {
 		BLI_ghash_free(filelist->selection_state, MEM_freeN, NULL);
@@ -1934,7 +1941,8 @@ unsigned int filelist_entry_select_set(
         const FileList *filelist, const FileDirEntry *entry, FileSelType select, unsigned int flag, FileCheckType check)
 {
 	/* Default NULL pointer if not found is fine here! */
-	unsigned int entry_flag = GET_UINT_FROM_POINTER(BLI_ghash_lookup(filelist->selection_state, entry->uuid));
+	void **es_p = BLI_ghash_lookup_p(filelist->selection_state, entry->uuid);
+	unsigned int entry_flag = es_p ? GET_UINT_FROM_POINTER(*es_p) : 0;
 	const unsigned int org_entry_flag = entry_flag;
 
 	BLI_assert(entry);
@@ -1958,13 +1966,18 @@ unsigned int filelist_entry_select_set(
 	}
 
 	if (entry_flag != org_entry_flag) {
-		if (entry_flag) {
+		if (es_p) {
+			if (entry_flag) {
+				*es_p = SET_UINT_IN_POINTER(entry_flag);
+			}
+			else {
+				BLI_ghash_remove(filelist->selection_state, entry->uuid, MEM_freeN, NULL);
+			}
+		}
+		else if (entry_flag) {
 			void *key = MEM_mallocN(sizeof(entry->uuid), __func__);
 			memcpy(key, entry->uuid, sizeof(entry->uuid));
-			BLI_ghash_reinsert(filelist->selection_state, key, SET_UINT_IN_POINTER(entry_flag), MEM_freeN, NULL);
-		}
-		else {
-			BLI_ghash_remove(filelist->selection_state, entry->uuid, MEM_freeN, NULL);
+			BLI_ghash_insert(filelist->selection_state, key, SET_UINT_IN_POINTER(entry_flag));
 		}
 	}
 
@@ -2509,7 +2522,8 @@ static void filelist_readjob_update(void *flrjv)
 	BLI_mutex_unlock(&flrj->lock);
 
 	if (new_nbr_entries) {
-		filelist_clear(flrj->filelist);
+		/* Do not clear selection cache, we can assume already 'selected' uuids are still valid! */
+		filelist_clear_ex(flrj->filelist, true, false);
 
 		flrj->filelist->need_sorting = true;
 		flrj->filelist->need_filtering = true;
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index 0ac1c46..173305a 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -83,6 +83,7 @@ int                 filelist_geticon(struct FileList *filelist, const int index,
 
 struct FileList *   filelist_new(short type);
 void                filelist_clear(struct FileList *filelist);
+void                filelist_clear_ex(struct FileList *filelist, const bool do_cache, const bool do_selection);
 void                filelist_free(struct FileList *filelist);
 
 const char *        filelist_dir(struct FileList *filelist);




More information about the Bf-blender-cvs mailing list