[Bf-blender-cvs] [fa81a425392] master: Cleanup: RNA ID enum utility function

Campbell Barton noreply at git.blender.org
Thu Nov 12 01:48:19 CET 2020


Commit: fa81a425392e334be5e4b9fd0b4c06cb8a2ad00b
Author: Campbell Barton
Date:   Thu Nov 12 11:43:35 2020 +1100
Branches: master
https://developer.blender.org/rBfa81a425392e334be5e4b9fd0b4c06cb8a2ad00b

Cleanup: RNA ID enum utility function

- Avoid calling `GS(id->name)` on each iteration.
- Remove unused arguments.
- Pass `const ID *` to the filter callback.

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

M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 50b4f39d8e1..9eedd5b2faa 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3968,39 +3968,40 @@ void wm_window_keymap(wmKeyConfig *keyconf)
  *
  * \{ */
 
-static bool rna_id_enum_filter_single(ID *id, void *user_data)
+static bool rna_id_enum_filter_single(const ID *id, void *user_data)
 {
   return (id != user_data);
 }
 
 /* Generic itemf's for operators that take library args */
-static const EnumPropertyItem *rna_id_itemf(bContext *UNUSED(C),
-                                            PointerRNA *UNUSED(ptr),
-                                            bool *r_free,
+static const EnumPropertyItem *rna_id_itemf(bool *r_free,
                                             ID *id,
                                             bool local,
-                                            bool (*filter_ids)(ID *id, void *user_data),
+                                            bool (*filter_ids)(const ID *id, void *user_data),
                                             void *user_data)
 {
   EnumPropertyItem item_tmp = {0}, *item = NULL;
   int totitem = 0;
   int i = 0;
 
-  for (; id; id = id->next) {
-    if ((filter_ids != NULL) && filter_ids(id, user_data) == false) {
-      i++;
-      continue;
-    }
-    if (local == false || !ID_IS_LINKED(id)) {
-      item_tmp.identifier = item_tmp.name = id->name + 2;
-      item_tmp.value = i++;
-
-      /* Show collection color tag icons in menus. */
-      if (GS(id->name) == ID_GR) {
-        item_tmp.icon = UI_icon_color_from_collection((Collection *)id);
+  if (id != NULL) {
+    const short id_type = GS(id->name);
+    for (; id; id = id->next) {
+      if ((filter_ids != NULL) && filter_ids(id, user_data) == false) {
+        i++;
+        continue;
       }
+      if (local == false || !ID_IS_LINKED(id)) {
+        item_tmp.identifier = item_tmp.name = id->name + 2;
+        item_tmp.value = i++;
 
-      RNA_enum_item_add(&item, &totitem, &item_tmp);
+        /* Show collection color tag icons in menus. */
+        if (id_type == ID_GR) {
+          item_tmp.icon = UI_icon_color_from_collection((Collection *)id);
+        }
+
+        RNA_enum_item_add(&item, &totitem, &item_tmp);
+      }
     }
   }
 
@@ -4012,119 +4013,111 @@ static const EnumPropertyItem *rna_id_itemf(bContext *UNUSED(C),
 
 /* can add more as needed */
 const EnumPropertyItem *RNA_action_itemf(bContext *C,
-                                         PointerRNA *ptr,
+                                         PointerRNA *UNUSED(ptr),
                                          PropertyRNA *UNUSED(prop),
                                          bool *r_free)
 {
-  return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->actions.first : NULL, false, NULL, NULL);
+
+  return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->actions.first : NULL, false, NULL, NULL);
 }
 #if 0 /* UNUSED */
 const EnumPropertyItem *RNA_action_local_itemf(bContext *C,
-                                               PointerRNA *ptr,
+                                               PointerRNA *UNUSED(ptr),
                                                PropertyRNA *UNUSED(prop),
                                                bool *r_free)
 {
-  return rna_id_itemf(C, ptr, r_free, C ? (ID *)CTX_data_main(C)->action.first : NULL, true);
+  return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->action.first : NULL, true);
 }
 #endif
 
 const EnumPropertyItem *RNA_collection_itemf(bContext *C,
-                                             PointerRNA *ptr,
+                                             PointerRNA *UNUSED(ptr),
                                              PropertyRNA *UNUSED(prop),
                                              bool *r_free)
 {
   return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->collections.first : NULL, false, NULL, NULL);
+      r_free, C ? (ID *)CTX_data_main(C)->collections.first : NULL, false, NULL, NULL);
 }
 const EnumPropertyItem *RNA_collection_local_itemf(bContext *C,
-                                                   PointerRNA *ptr,
+                                                   PointerRNA *UNUSED(ptr),
                                                    PropertyRNA *UNUSED(prop),
                                                    bool *r_free)
 {
   return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->collections.first : NULL, true, NULL, NULL);
+      r_free, C ? (ID *)CTX_data_main(C)->collections.first : NULL, true, NULL, NULL);
 }
 
 const EnumPropertyItem *RNA_image_itemf(bContext *C,
-                                        PointerRNA *ptr,
+                                        PointerRNA *UNUSED(ptr),
                                         PropertyRNA *UNUSED(prop),
                                         bool *r_free)
 {
-  return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->images.first : NULL, false, NULL, NULL);
+  return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->images.first : NULL, false, NULL, NULL);
 }
 const EnumPropertyItem *RNA_image_local_itemf(bContext *C,
-                                              PointerRNA *ptr,
+                                              PointerRNA *UNUSED(ptr),
                                               PropertyRNA *UNUSED(prop),
                                               bool *r_free)
 {
-  return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->images.first : NULL, true, NULL, NULL);
+  return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->images.first : NULL, true, NULL, NULL);
 }
 
 const EnumPropertyItem *RNA_scene_itemf(bContext *C,
-                                        PointerRNA *ptr,
+                                        PointerRNA *UNUSED(ptr),
                                         PropertyRNA *UNUSED(prop),
                                         bool *r_free)
 {
-  return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->scenes.first : NULL, false, NULL, NULL);
+  return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->scenes.first : NULL, false, NULL, NULL);
 }
 const EnumPropertyItem *RNA_scene_local_itemf(bContext *C,
-                                              PointerRNA *ptr,
+                                              PointerRNA *UNUSED(ptr),
                                               PropertyRNA *UNUSED(prop),
                                               bool *r_free)
 {
-  return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->scenes.first : NULL, true, NULL, NULL);
+  return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->scenes.first : NULL, true, NULL, NULL);
 }
 const EnumPropertyItem *RNA_scene_without_active_itemf(bContext *C,
-                                                       PointerRNA *ptr,
+                                                       PointerRNA *UNUSED(ptr),
                                                        PropertyRNA *UNUSED(prop),
                                                        bool *r_free)
 {
   Scene *scene_active = C ? CTX_data_scene(C) : NULL;
-  return rna_id_itemf(C,
-                      ptr,
-                      r_free,
+  return rna_id_itemf(r_free,
                       C ? (ID *)CTX_data_main(C)->scenes.first : NULL,
                       false,
                       rna_id_enum_filter_single,
                       scene_active);
 }
 const EnumPropertyItem *RNA_movieclip_itemf(bContext *C,
-                                            PointerRNA *ptr,
+                                            PointerRNA *UNUSED(ptr),
                                             PropertyRNA *UNUSED(prop),
                                             bool *r_free)
 {
   return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->movieclips.first : NULL, false, NULL, NULL);
+      r_free, C ? (ID *)CTX_data_main(C)->movieclips.first : NULL, false, NULL, NULL);
 }
 const EnumPropertyItem *RNA_movieclip_local_itemf(bContext *C,
-                                                  PointerRNA *ptr,
+                                                  PointerRNA *UNUSED(ptr),
                                                   PropertyRNA *UNUSED(prop),
                                                   bool *r_free)
 {
   return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->movieclips.first : NULL, true, NULL, NULL);
+      r_free, C ? (ID *)CTX_data_main(C)->movieclips.first : NULL, true, NULL, NULL);
 }
 
 const EnumPropertyItem *RNA_mask_itemf(bContext *C,
-                                       PointerRNA *ptr,
+                                       PointerRNA *UNUSED(ptr),
                                        PropertyRNA *UNUSED(prop),
                                        bool *r_free)
 {
-  return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->masks.first : NULL, false, NULL, NULL);
+  return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->masks.first : NULL, false, NULL, NULL);
 }
 const EnumPropertyItem *RNA_mask_local_itemf(bContext *C,
-                                             PointerRNA *ptr,
+                                             PointerRNA *UNUSED(ptr),
                                              PropertyRNA *UNUSED(prop),
                                              bool *r_free)
 {
-  return rna_id_itemf(
-      C, ptr, r_free, C ? (ID *)CTX_data_main(C)->masks.first : NULL, true, NULL, NULL);
+  return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->masks.first : NULL, true, NULL, NULL);
 }
 
 /** \} */



More information about the Bf-blender-cvs mailing list