[pygobject] Optimize connection of Python-implemented signals



commit e220706b3e4d9fd454613fbfe1e60e7e1da94ae0
Author: Daniel Drake <dsd laptop org>
Date:   Mon Mar 18 15:38:19 2013 -0600

    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

 gi/_gobject/pygobject.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index a39ef60..f300c1b 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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]