aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-08-14 12:59:41 +0200
committerChristian Tismer <tismer@stackless.com>2022-08-15 08:41:59 +0200
commit01e048763a372677c358172a66232f15b09a1021 (patch)
tree40a3476f81046b7a9e42216d91879e07360e94c0
parent0f5dcb03eb258280acd10a0f4f2889301a9ef365 (diff)
PyEnum: Accelerate item access
With the transition to Python 3.11, access to enum items has become slower by the replacement of direct item access by Python properties, involving unnecessarily the use of Python code. When we are in charge of Enum item access, we circumvent the slower property access by using the internal mapping directly. Task-number: PYSIDE-1735 Change-Id: Iabe045be09df847d9587e9d3f6913e9610f5695e Pick-to: 6.3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/shiboken6/libshiboken/sbkenum.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/sources/shiboken6/libshiboken/sbkenum.cpp b/sources/shiboken6/libshiboken/sbkenum.cpp
index a36dfd176..4a5f50dce 100644
--- a/sources/shiboken6/libshiboken/sbkenum.cpp
+++ b/sources/shiboken6/libshiboken/sbkenum.cpp
@@ -695,13 +695,17 @@ newItem(PyTypeObject *enumType, long itemValue, const char *itemName)
if (useOldEnum)
return newItemOld(enumType, itemValue, itemName);
- if (!itemName) {
- //PyObject *enumObj = getEnumItemFromValue(enumType, itemValue);
- PyObject *enumObj = PyObject_CallFunction(reinterpret_cast<PyObject *>(enumType), "i", itemValue);
- //if (enumObj)
- return enumObj;
- }
- return PyObject_GetAttrString(reinterpret_cast<PyObject *>(enumType), itemName);
+ auto *obEnumType = reinterpret_cast<PyObject *>(enumType);
+ if (!itemName)
+ return PyObject_CallFunction(obEnumType, "i", itemValue);
+
+ static PyObject *const _member_map_ = String::createStaticString("_member_map_");
+ auto *member_map = PyDict_GetItem(enumType->tp_dict, _member_map_);
+ if (!(member_map && PyDict_Check(member_map)))
+ return nullptr;
+ auto *result = PyDict_GetItemString(member_map, itemName);
+ Py_XINCREF(result);
+ return result;
}
} // namespace Shiboken