[Bf-blender-cvs] [f652eb8] tmp-id-users: Minor edits, comments, cleanup & style

Campbell Barton noreply at git.blender.org
Wed Jan 6 17:24:12 CET 2016


Commit: f652eb867e9d92ef800c09fbbdff8590869d7fd0
Author: Campbell Barton
Date:   Thu Jan 7 03:16:54 2016 +1100
Branches: tmp-id-users
https://developer.blender.org/rBf652eb867e9d92ef800c09fbbdff8590869d7fd0

Minor edits, comments, cleanup & style

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

M	source/blender/python/intern/bpy_rna_id_collection.c

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

diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c
index 6846e0a..8467c74 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -49,14 +49,16 @@
 #include "bpy_rna.h"
 
 typedef struct IDUserMapData {
-	PyObject *py_id_key;
-	ID *orig_id_key;
+	/* place-holder key only used for lookups to avoid creating new data only for lookups
+	 * (never return its contents) */
+	PyObject *py_id_key_lookup_only;
 
-	ID *id_curr;
+	/* we loop over data-blocks that this ID points to (do build a reverse lookup table) */
 	PyObject *py_id_curr;
+	ID *id_curr;
 
-	PyObject *user_map;
-	bool is_restricted;
+	PyObject *user_map;     /* set to fill in as we iterate */
+	bool is_subset;         /* true when we're only mapping a subset of all the ID's (subset arg is passed) */
 } IDUserMapData;
 
 static bool foreach_libblock_id_user_map_callback(void *user_data, ID **id_p, int UNUSED(cb_flag))
@@ -65,13 +67,15 @@ static bool foreach_libblock_id_user_map_callback(void *user_data, ID **id_p, in
 
 	if (*id_p) {
 		PyObject *set;
-		PyObject *key = data->py_id_key;
+		PyObject *key = data->py_id_key_lookup_only;
 
-		/* pyrna_struct_hash() uses ptr.data only, but pyrna_struct_richcmp() uses also ptr.type, so we need to create
-		 * a valid PointerRNA here... */
+		/* pyrna_struct_hash() uses ptr.data only,
+		 * but pyrna_struct_richcmp() uses also ptr.type,
+		 * so we need to create a valid PointerRNA here...
+		 */
 		RNA_id_pointer_create(*id_p, &((BPy_StructRNA *)key)->ptr);
 
-		if (data->is_restricted) {
+		if (data->is_subset) {
 			if ((set = PyDict_GetItem(data->user_map, key))) {
 				if (data->py_id_curr == NULL) {
 					data->py_id_curr = pyrna_id_CreatePyObject(data->id_curr);
@@ -130,7 +134,10 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
 	ListBase *lb_array[MAX_LIBARRAY];
 	int lb_idx;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:user_map", (char **)kwlist, &iter_id)) {
+	if (!PyArg_ParseTupleAndKeywords(
+	        args, kwds, "|O:user_map", (char **)kwlist,
+	        &iter_id))
+	{
 		return NULL;
 	}
 
@@ -141,7 +148,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
 		PyObject **ref_id = PySequence_Fast_ITEMS(fast_it);
 		Py_ssize_t iter_id_len = PySequence_Fast_GET_SIZE(fast_it);
 
-		data_cb.is_restricted = true;
+		data_cb.is_subset = true;
 		for (; iter_id_len; ref_id++, iter_id_len--) {
 			PyObject *set = PySet_New(NULL);
 			PyDict_SetItem(user_map, *ref_id, set);
@@ -157,8 +164,8 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
 			/* One-time init, ID is just used as placeholder here, we abuse this in iterator callback
 			 * to avoid having to rebuild a complete bpyrna object each time for the key searching
 			 * (where only ID pointer value is used). */
-			if (data_cb.py_id_key == NULL) {
-				data_cb.py_id_key = pyrna_id_CreatePyObject(id);
+			if (data_cb.py_id_key_lookup_only == NULL) {
+				data_cb.py_id_key_lookup_only = pyrna_id_CreatePyObject(id);
 			}
 
 			data_cb.id_curr = id;
@@ -170,14 +177,15 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
 		}
 	}
 
-	Py_XDECREF(data_cb.py_id_key);
+	Py_XDECREF(data_cb.py_id_key_lookup_only);
 
 	return user_map;
 }
 
 int BPY_rna_id_collection_module(PyObject *mod_par)
 {
-	static PyMethodDef user_map = {"user_map", (PyCFunction)bpy_user_map, METH_VARARGS | METH_KEYWORDS, bpy_user_map_doc};
+	static PyMethodDef user_map = {
+	    "user_map", (PyCFunction)bpy_user_map, METH_VARARGS | METH_KEYWORDS, bpy_user_map_doc};
 
 	PyModule_AddObject(mod_par, "_rna_id_collection_user_map", PyCFunction_New(&user_map, NULL));




More information about the Bf-blender-cvs mailing list