[gjs/wip/walters/632938-use-g-irepository-get-object-gtype-interfaces: 91/91] object: Use g_irepository_get_object_gtype_interfaces



commit d6abc579d3d551b01bf2fd26909a3c8b3b899f09
Author: Colin Walters <walters verbum org>
Date:   Fri Oct 22 18:09:16 2010 -0400

    object: Use g_irepository_get_object_gtype_interfaces
    
    Push the logic for this down into libgirepository, where we
    can more easily cache/optimize it.
    
    [skip ci] - Won't compile until corresponding patch is merged into
    gobject-introspection.
    
    Closes #55

 gi/object.cpp | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 1c3b7c33..428b15e6 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -725,8 +725,11 @@ bool ObjectPrototype::resolve_no_info(JSContext* cx, JS::HandleObject obj,
                                       JS::HandleId id, bool* resolved,
                                       const char* name,
                                       ResolveWhat resolve_props) {
+    GIInterfaceInfo *interfaces;
     guint n_interfaces;
     guint i;
+    g_irepository_get_object_gtype_interfaces(nullptr, m_gtype, &n_interfaces,
+        &interfaces);
 
     GjsAutoChar canonical_name;
     if (resolve_props == ConsiderMethodsAndProperties) {
@@ -734,24 +737,16 @@ bool ObjectPrototype::resolve_no_info(JSContext* cx, JS::HandleObject obj,
         canonicalize_key(canonical_name);
     }
 
-    GType *interfaces = g_type_interfaces(m_gtype, &n_interfaces);
     for (i = 0; i < n_interfaces; i++) {
-        GjsAutoInterfaceInfo iface_info =
-            g_irepository_find_by_gtype(nullptr, interfaces[i]);
-        if (!iface_info)
-            continue;
-
+        GIInterfaceInfo *iface_info = interfaces + i;
         GjsAutoFunctionInfo method_info =
             g_interface_info_find_method(iface_info, name);
         if (method_info != NULL) {
             if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) {
-                if (!gjs_define_function(cx, obj, m_gtype, method_info)) {
-                    g_free(interfaces);
+                if (!gjs_define_function(cx, obj, m_gtype, method_info))
                     return false;
-                }
 
                 *resolved = true;
-                g_free(interfaces);
                 return true;
             }
         }
@@ -762,14 +757,11 @@ bool ObjectPrototype::resolve_no_info(JSContext* cx, JS::HandleObject obj,
         /* If the name refers to a GObject property, lazily define the property
          * in JS as we do below in the real resolve hook. We ignore fields here
          * because I don't think interfaces can have fields */
-        if (is_ginterface_property_name(iface_info, canonical_name)) {
-            g_free(interfaces);
+        if (is_ginterface_property_name(iface_info, canonical_name))
             return lazy_define_gobject_property(cx, obj, id, resolved, name);
-        }
     }
 
     *resolved = false;
-    g_free(interfaces);
     return true;
 }
 
@@ -934,8 +926,8 @@ bool ObjectPrototype::resolve_impl(JSContext* context, JS::HandleObject obj,
 
     /**
      * Search through any interfaces implemented by the GType;
-     * this could be done better.  See
-     * https://bugzilla.gnome.org/show_bug.cgi?id=632922
+     * See https://bugzilla.gnome.org/show_bug.cgi?id=632922
+     * for background on why we need to do this.
      */
     if (!method_info)
         return resolve_no_info(context, obj, id, resolved, name.get(),


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