diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2019-01-18 20:07:17 +0100 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2019-01-18 20:15:08 +0100 |
commit | 48f80f8b763d84294c73f428bf7ede39cef57027 (patch) | |
tree | c317fe59a946d704b9333e06607e322afb6e8616 /gi | |
parent | 7fcc843c41460451200d2dcc065d446f81f4dbd9 (diff) | |
download | pygobject-48f80f8b763d84294c73f428bf7ede39cef57027.tar.gz |
GObject.Value: add a static helper for fetching the GType
The field marshalling code is slow and doesn't do any caching at all
which in turn makes accessing Value.g_type slow.
Add a static helper function for fetching the GType and use that instead.
This reduced the time for creating a GValue + setting it by ~30%
Diffstat (limited to 'gi')
-rw-r--r-- | gi/gimodule.c | 2 | ||||
-rw-r--r-- | gi/overrides/GObject.py | 16 | ||||
-rw-r--r-- | gi/pygi-value.c | 16 | ||||
-rw-r--r-- | gi/pygi-value.h | 1 |
4 files changed, 30 insertions, 5 deletions
diff --git a/gi/gimodule.c b/gi/gimodule.c index 7ff9b0eb..2be5e478 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -2291,6 +2291,8 @@ static PyMethodDef _gi_functions[] = { (PyCFunction)pyg__install_metaclass, METH_O }, { "_gvalue_get", (PyCFunction)pyg__gvalue_get, METH_O }, + { "_gvalue_get_type", + (PyCFunction)pyg__gvalue_get_type, METH_O }, { "_gvalue_set", (PyCFunction)pyg__gvalue_set, METH_VARARGS }, { NULL, NULL, 0 } diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py index 4cc08a9a..04b5be65 100644 --- a/gi/overrides/GObject.py +++ b/gi/overrides/GObject.py @@ -209,8 +209,14 @@ class Value(GObjectModule.Value): if py_value is not None: self.set_value(py_value) + @property + def __g_type(self): + # XXX: This is the same as self.g_type, but the field marshalling + # code is currently very slow. + return _gi._gvalue_get_type(self) + def set_boxed(self, boxed): - if not self.g_type.is_a(TYPE_BOXED): + if not self.__g_type.is_a(TYPE_BOXED): warnings.warn('Calling set_boxed() on a non-boxed type deprecated', PyGIDeprecationWarning, stacklevel=2) # Workaround the introspection marshalers inability to know @@ -219,13 +225,13 @@ class Value(GObjectModule.Value): _gi._gvalue_set(self, boxed) def get_boxed(self): - if not self.g_type.is_a(TYPE_BOXED): + if not self.__g_type.is_a(TYPE_BOXED): warnings.warn('Calling get_boxed() on a non-boxed type deprecated', PyGIDeprecationWarning, stacklevel=2) return _gi._gvalue_get(self) def set_value(self, py_value): - gtype = self.g_type + gtype = self.__g_type if gtype == _gi.TYPE_INVALID: raise TypeError("GObject.Value needs to be initialized first") @@ -288,7 +294,7 @@ class Value(GObjectModule.Value): _gi._gvalue_set(self, py_value) def get_value(self): - gtype = self.g_type + gtype = self.__g_type if gtype == TYPE_BOOLEAN: return self.get_boolean() @@ -340,7 +346,7 @@ class Value(GObjectModule.Value): return _gi._gvalue_get(self) def __repr__(self): - return '<Value (%s) %s>' % (self.g_type.name, self.get_value()) + return '<Value (%s) %s>' % (self.__g_type.name, self.get_value()) Value = override(Value) diff --git a/gi/pygi-value.c b/gi/pygi-value.c index 93669345..8376231e 100644 --- a/gi/pygi-value.c +++ b/gi/pygi-value.c @@ -887,6 +887,22 @@ pyg__gvalue_get(PyObject *module, PyObject *pygvalue) } PyObject * +pyg__gvalue_get_type(PyObject *module, PyObject *pygvalue) +{ + GValue *value; + GType type; + + if (!pyg_boxed_check (pygvalue, G_TYPE_VALUE)) { + PyErr_SetString (PyExc_TypeError, "Expected GValue argument."); + return NULL; + } + + value = pyg_boxed_get (pygvalue, GValue); + type = G_VALUE_TYPE (value); + return pyg_type_wrapper_new (type); +} + +PyObject * pyg__gvalue_set(PyObject *module, PyObject *args) { PyObject *pygvalue; diff --git a/gi/pygi-value.h b/gi/pygi-value.h index 6450112d..5778a22c 100644 --- a/gi/pygi-value.h +++ b/gi/pygi-value.h @@ -45,6 +45,7 @@ PyObject *pygi_value_to_py_basic_type (const GValue *value, PyObject *pyg__gvalue_get(PyObject *module, PyObject *pygvalue); PyObject *pyg__gvalue_set(PyObject *module, PyObject *args); +PyObject *pyg__gvalue_get_type(PyObject *module, PyObject *pygvalue); G_END_DECLS |