diff options
author | Daniel Drake <dsd@laptop.org> | 2013-03-18 15:38:19 -0600 |
---|---|---|
committer | Martin Pitt <martinpitt@gnome.org> | 2013-04-18 08:22:19 +0200 |
commit | e220706b3e4d9fd454613fbfe1e60e7e1da94ae0 (patch) | |
tree | 4e9de1ced0404f81f6ccb065192b20891901cf11 | |
parent | e91b35d72f93678a79623347dce271148d57046f (diff) | |
download | pygobject-e220706b3e4d9fd454613fbfe1e60e7e1da94ae0.tar.gz |
Optimize connection of Python-implemented signals
Like properties, when working with signals we must detect if the
signal is implemented in a Python class or if it originates from the
gi repository, and act accordingly.
Asking the gi repository if it can find a signal that is implemented
in a Python class (it can't) takes a considerable amount of CPU time.
Use g_signal_query() to find out which GType implements the signal.
Then perform a simple test to see if this type is implemented at the
Python level, allowing us to to skip the GI querying in this case.
https://bugzilla.gnome.org/show_bug.cgi?id=696143
-rw-r--r-- | gi/_gobject/pygobject.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c index a39ef60d..f300c1b4 100644 --- a/gi/_gobject/pygobject.c +++ b/gi/_gobject/pygobject.c @@ -1639,8 +1639,9 @@ connect_helper(PyGObject *self, gchar *name, PyObject *callback, PyObject *extra { guint sigid; GQuark detail = 0; - GClosure *closure; + GClosure *closure = NULL; gulong handlerid; + GSignalQuery query_info; if (!g_signal_parse_name(name, G_OBJECT_TYPE(self->obj), &sigid, &detail, TRUE)) { @@ -1652,9 +1653,19 @@ connect_helper(PyGObject *self, gchar *name, PyObject *callback, PyObject *extra return NULL; } - closure = pygi_signal_closure_new(self, name, callback, extra_args, object); - if (closure == NULL) - closure = pyg_closure_new(callback, extra_args, object); + g_signal_query (sigid, &query_info); + if (!pyg_gtype_is_custom (query_info.itype)) { + /* The signal is implemented by a non-Python class, probably + * something in the gi repository. */ + closure = pygi_signal_closure_new (self, name, callback, extra_args, + object); + } + + if (!closure) { + /* The signal is either implemented at the Python level, or it comes + * from a foreign class that we don't have introspection data for. */ + closure = pyg_closure_new (callback, extra_args, object); + } pygobject_watch_closure((PyObject *)self, closure); handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail, |