WM: unneeded alloc the operator-type iterator
authorCampbell Barton <ideasman42@gmail.com>
Tue, 28 Oct 2014 14:41:05 +0000 (15:41 +0100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 28 Oct 2014 14:41:05 +0000 (15:41 +0100)
source/blender/editors/interface/interface_templates.c
source/blender/editors/space_view3d/view3d_toolbar.c
source/blender/python/intern/bpy_operator.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_operators.c
source/blenderplayer/bad_level_call_stubs/stubs.c

index 25e30d4cd7561f53a8805128b4b29fecbc609cf1..6c054b93351eea2a01a5d02bb32f3fa90859fece 100644 (file)
@@ -3246,10 +3246,10 @@ static void operator_call_cb(bContext *C, void *UNUSED(arg1), void *arg2)
 
 static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items)
 {
-       GHashIterator *iter = WM_operatortype_iter();
+       GHashIterator iter;
 
-       for (; !BLI_ghashIterator_done(iter); BLI_ghashIterator_step(iter)) {
-               wmOperatorType *ot = BLI_ghashIterator_getValue(iter);
+       for (WM_operatortype_iter(&iter); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
+               wmOperatorType *ot = BLI_ghashIterator_getValue(&iter);
 
                if ((ot->flag & OPTYPE_INTERNAL) && (G.debug & G_DEBUG_WM) == 0)
                        continue;
@@ -3276,7 +3276,6 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char
                        }
                }
        }
-       BLI_ghashIterator_free(iter);
 }
 
 void uiOperatorSearch_But(uiBut *but)
index 3f7f12d20207abf338ba4a7d616acd0ec848d595..11e91800f88b3e5ed4bca1ea0b073b30d77fcf0d 100644 (file)
@@ -151,10 +151,10 @@ static void operator_call_cb(struct bContext *C, void *arg_listbase, void *arg2)
 
 static void operator_search_cb(const struct bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items)
 {
-       GHashIterator *iter = WM_operatortype_iter();
+       GHashIterator iter;
 
-       for (; !BLI_ghashIterator_done(iter); BLI_ghashIterator_step(iter)) {
-               wmOperatorType *ot = BLI_ghashIterator_getValue(iter);
+       for (WM_operatortype_iter(&iter); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
+               wmOperatorType *ot = BLI_ghashIterator_getValue(&iter);
 
                if (BLI_strcasestr(ot->name, str)) {
                        if (WM_operator_poll((bContext *)C, ot)) {
@@ -164,7 +164,6 @@ static void operator_search_cb(const struct bContext *C, void *UNUSED(arg), cons
                        }
                }
        }
-       BLI_ghashIterator_free(iter);
 }
 
 
index 1e97d7aeada71a4b0f304e9516231fadc799abb7..86282f251c3f2ef597db5f3b7fa856e3c96aee2d 100644 (file)
@@ -367,17 +367,17 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
 
 static PyObject *pyop_dir(PyObject *UNUSED(self))
 {
-       GHashIterator *iter = WM_operatortype_iter();
-       PyObject *list = PyList_New(0), *name;
+       GHashIterator iter;
+       PyObject *list;
+       int i;
 
-       for ( ; !BLI_ghashIterator_done(iter); BLI_ghashIterator_step(iter)) {
-               wmOperatorType *ot = BLI_ghashIterator_getValue(iter);
+       WM_operatortype_iter(&iter);
+       list = PyList_New(BLI_ghash_size(iter.gh));
 
-               name = PyUnicode_FromString(ot->idname);
-               PyList_Append(list, name);
-               Py_DECREF(name);
+       for (i = 0; !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter), i++) {
+               wmOperatorType *ot = BLI_ghashIterator_getValue(&iter);
+               PyList_SET_ITEM(list, i, PyUnicode_FromString(ot->idname));
        }
-       BLI_ghashIterator_free(iter);
 
        return list;
 }
index e1cd334637a1177be21f0445e0ae16b4f98f5cbf..cf9f94aff251cd06a7d505694afb8e36762c2285 100644 (file)
@@ -47,6 +47,7 @@ extern "C" {
 #endif
 
 struct bContext;
+struct GHashIterator;
 struct IDProperty;
 struct wmEvent;
 struct wmEventHandler;
@@ -223,7 +224,7 @@ void                WM_operator_stack_clear(struct wmWindowManager *wm);
 void           WM_operator_handlers_clear(wmWindowManager *wm, struct wmOperatorType *ot);
 
 struct wmOperatorType *WM_operatortype_find(const char *idname, bool quiet);
-struct GHashIterator  *WM_operatortype_iter(void);
+void        WM_operatortype_iter(struct GHashIterator *ghi);
 void           WM_operatortype_append(void (*opfunc)(struct wmOperatorType *));
 void           WM_operatortype_append_ptr(void (*opfunc)(struct wmOperatorType *, void *), void *userdata);
 void           WM_operatortype_append_macro_ptr(void (*opfunc)(struct wmOperatorType *, void *), void *userdata);
index 68aad2dbda663cd9d6f7383044cec760c92ca480..77f6028dd0657d99f423855e23ece457fd3d91cb 100644 (file)
@@ -147,9 +147,9 @@ wmOperatorType *WM_operatortype_find(const char *idname, bool quiet)
 }
 
 /* caller must free */
-GHashIterator *WM_operatortype_iter(void)
+void WM_operatortype_iter(GHashIterator *ghi)
 {
-       return BLI_ghashIterator_new(global_ops_hash);
+       BLI_ghashIterator_init(ghi, global_ops_hash);
 }
 
 /* all ops in 1 list (for time being... needs evaluation later) */
index 0846e37178d72bb3121a510cb7092bc35af7480f..233ae79243a8bfd0b7b9cb3bd010d6fb586225dd 100644 (file)
@@ -597,7 +597,7 @@ void RE_FreePersistentData(void) RET_NONE
 
 /* python */
 struct wmOperatorType *WM_operatortype_find(const char *idname, bool quiet) RET_NULL
-struct GHashIterator *WM_operatortype_iter() RET_NULL
+void WM_operatortype_iter(struct GHashIterator *ghi) RET_NONE
 struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *ot, const char *idname) RET_NULL
 int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties, struct ReportList *reports, const bool is_undo) RET_ZERO
 void WM_operatortype_remove_ptr(struct wmOperatorType *ot) RET_NONE