aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-07-08 14:26:04 +0200
committerChristian Tismer <tismer@stackless.com>2020-07-09 11:34:36 +0200
commitfb2dc48389c1099bef3aaed97f16ce2bd1b90fee (patch)
treefd3266c3f422170df2b92bd494b7e49b7bcf712e /sources/shiboken2/libshiboken
parent39c6018e484d2a6850d239de03fef89df730f357 (diff)
shiboken: optimize method override strings
The override strings in bindingmanager were based upon pure C strings for a long time. There was some mild overhead of creating PyObject all the time. With the upcoming name mangling of Selectable Features, this becomes even a bit more inefficient when strings also get mangled. With Python strings this is just a dict lookup. This patch uses the same machinery as `Shiboken::PyName`. Task-number: PYSIDE-1019 Change-Id: I4eed7222371dadeed0e9ba98cc7970e726ffc044 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/libshiboken')
-rw-r--r--sources/shiboken2/libshiboken/bindingmanager.cpp9
-rw-r--r--sources/shiboken2/libshiboken/bindingmanager.h2
-rw-r--r--sources/shiboken2/libshiboken/sbkstring.cpp6
3 files changed, 8 insertions, 9 deletions
diff --git a/sources/shiboken2/libshiboken/bindingmanager.cpp b/sources/shiboken2/libshiboken/bindingmanager.cpp
index 1ab8dd089..1c38da81c 100644
--- a/sources/shiboken2/libshiboken/bindingmanager.cpp
+++ b/sources/shiboken2/libshiboken/bindingmanager.cpp
@@ -273,7 +273,7 @@ SbkObject *BindingManager::retrieveWrapper(const void *cptr)
return iter->second;
}
-PyObject *BindingManager::getOverride(const void *cptr, const char *methodName)
+PyObject *BindingManager::getOverride(const void *cptr, PyObject *methodName)
{
SbkObject *wrapper = retrieveWrapper(cptr);
// The refcount can be 0 if the object is dieing and someone called
@@ -282,15 +282,14 @@ PyObject *BindingManager::getOverride(const void *cptr, const char *methodName)
return nullptr;
if (wrapper->ob_dict) {
- PyObject *method = PyDict_GetItemString(wrapper->ob_dict, methodName);
+ PyObject *method = PyDict_GetItem(wrapper->ob_dict, methodName);
if (method) {
Py_INCREF(reinterpret_cast<PyObject *>(method));
return method;
}
}
- Shiboken::AutoDecRef pyMethodName(Shiboken::String::fromCString(methodName));
- PyObject *method = PyObject_GetAttr(reinterpret_cast<PyObject *>(wrapper), pyMethodName);
+ PyObject *method = PyObject_GetAttr(reinterpret_cast<PyObject *>(wrapper), methodName);
if (method && PyMethod_Check(method)
&& PyMethod_GET_SELF(method) == reinterpret_cast<PyObject *>(wrapper)) {
@@ -302,7 +301,7 @@ PyObject *BindingManager::getOverride(const void *cptr, const char *methodName)
for (int i = 1; i < PyTuple_GET_SIZE(mro) - 1; i++) {
auto *parent = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, i));
if (parent->tp_dict) {
- defaultMethod = PyDict_GetItem(parent->tp_dict, pyMethodName);
+ defaultMethod = PyDict_GetItem(parent->tp_dict, methodName);
if (defaultMethod && PyMethod_GET_FUNCTION(method) != defaultMethod)
return method;
}
diff --git a/sources/shiboken2/libshiboken/bindingmanager.h b/sources/shiboken2/libshiboken/bindingmanager.h
index ba5535347..0bcde196f 100644
--- a/sources/shiboken2/libshiboken/bindingmanager.h
+++ b/sources/shiboken2/libshiboken/bindingmanager.h
@@ -73,7 +73,7 @@ public:
void addToDeletionInMainThread(const DestructorEntry &);
SbkObject *retrieveWrapper(const void *cptr);
- PyObject *getOverride(const void *cptr, const char *methodName);
+ PyObject *getOverride(const void *cptr, PyObject *methodName);
void addClassInheritance(SbkObjectType *parent, SbkObjectType *child);
/**
diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp
index 38bb105d0..7fb7d5730 100644
--- a/sources/shiboken2/libshiboken/sbkstring.cpp
+++ b/sources/shiboken2/libshiboken/sbkstring.cpp
@@ -41,7 +41,7 @@
#include "sbkstaticstrings_p.h"
#include "autodecref.h"
-#include <vector>
+#include <set>
namespace Shiboken
{
@@ -236,7 +236,7 @@ Py_ssize_t len(PyObject *str)
// But this is a global fault in shiboken. We are missing a true
// finalization like in all other modules.
-using StaticStrings = std::vector<PyObject *>;
+using StaticStrings = std::set<PyObject *>;
static StaticStrings &staticStrings()
{
@@ -256,7 +256,7 @@ PyObject *createStaticString(const char *str)
PyErr_Print();
Py_FatalError("unexpected error in createStaticString()");
}
- staticStrings().push_back(result);
+ staticStrings().insert(result);
return result;
}