Cleanup: use Map for operator types

This simplifies the code, makes it more type safe and also makes it
easier to use the construct-on-first-use-idiom.

Pull Request: https://projects.blender.org/blender/blender/pulls/121170
This commit is contained in:
Jacques Lucke
2024-04-27 21:44:55 +02:00
parent f48becc7d0
commit 71ba360ddc
7 changed files with 39 additions and 57 deletions

View File

@@ -392,16 +392,13 @@ static PyObject *pyop_as_string(PyObject * /*self*/, PyObject *args)
static PyObject *pyop_dir(PyObject * /*self*/)
{
GHashIterator iter;
PyObject *list;
int i;
const wmOperatorTypeMap &map = WM_operatortype_map();
PyObject *list = PyList_New(map.size());
WM_operatortype_iter(&iter);
list = PyList_New(BLI_ghash_len(iter.gh));
for (i = 0; !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter), i++) {
wmOperatorType *ot = static_cast<wmOperatorType *>(BLI_ghashIterator_getValue(&iter));
int i = 0;
for (wmOperatorType *ot : map.values()) {
PyList_SET_ITEM(list, i, PyUnicode_FromString(ot->idname));
i++;
}
return list;