diff options
author | Daniel Drake <dsd@laptop.org> | 2013-03-18 14:25:45 -0600 |
---|---|---|
committer | Simon Feltman <sfeltman@src.gnome.org> | 2013-04-16 19:20:50 -0700 |
commit | 8981ea0422c6837d488311dafe8937593372e736 (patch) | |
tree | 17000ad8a4d5539b66e5aff56fac69615df39e7c | |
parent | 266e389ff90d982151bae3ac22b9b8b0739f520f (diff) | |
download | pygobject-8981ea0422c6837d488311dafe8937593372e736.tar.gz |
Optimize property get/set when using GObject.props
Skip GI repository lookup for properties defined on Python
defined GObject types.
Signed-off-by: Simon Feltman <sfeltman@src.gnome.org>
https://bugzilla.gnome.org/show_bug.cgi?id=696143
-rw-r--r-- | gi/_gobject/pygobject.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c index 102041c0..c92a3f75 100644 --- a/gi/_gobject/pygobject.c +++ b/gi/_gobject/pygobject.c @@ -299,15 +299,16 @@ PyGProps_getattro(PyGProps *self, PyObject *attr) return pyg_param_spec_new(pspec); } - /* See if the property's class is from the gi repository. If so, - * use gi to correctly read the property value. */ - ret = pygi_get_property_value (self->pygobject, pspec); - if (ret != NULL) { - return ret; + if (!pyg_gtype_is_custom (pspec->owner_type)) { + /* The GType is not implemented at the Python level: see if we can + * read the property value via gi. */ + ret = pygi_get_property_value (self->pygobject, pspec); + if (ret) + return ret; } - - /* If we reach here, it must be a property defined outside of gi. - * Just do a straightforward read. */ + + /* The GType is implemented in Python, or we failed to read it via gi: + * do a straightforward read. */ g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec)); pyg_begin_allow_threads; g_object_get_property(self->pygobject->obj, pspec->name, &value); @@ -402,18 +403,18 @@ PyGProps_setattro(PyGProps *self, PyObject *attr, PyObject *pvalue) if (!pspec) { return PyObject_GenericSetAttr((PyObject *)self, attr, pvalue); } - - /* See if the property's class is from the gi repository. If so, - * use gi to correctly read the property value. */ - ret = pygi_set_property_value (self->pygobject, pspec, pvalue); - if (ret == 0) - return 0; - else if (ret == -1) - if (PyErr_Occurred()) + if (!pyg_gtype_is_custom (pspec->owner_type)) { + /* This GType is not implemented in Python: see if we can set the + * property via gi. */ + ret = pygi_set_property_value (self->pygobject, pspec, pvalue); + if (ret == 0) + return 0; + else if (ret == -1 && PyErr_Occurred()) return -1; + } - /* If we reach here, it must be a property defined outside of gi. - * Just do a straightforward set. */ + /* This GType is implemented in Python, or we failed to set it via gi: + * do a straightforward set. */ if (!set_property_from_pspec(obj, pspec, pvalue)) return -1; |