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



commit 43067109eda64e015549e115c275aadd6ac18573
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.
    
    Closes #55

 configure.ac  |  2 +-
 gi/object.cpp | 24 ++++++++----------------
 2 files changed, 9 insertions(+), 17 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1e58000c..ba4cbaea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,7 +63,7 @@ AX_VALGRIND_CHECK
 # Checks for libraries.
 m4_define(glib_required_version, 2.58.0)
 
-GOBJECT_INTROSPECTION_REQUIRE([1.41.4])
+GOBJECT_INTROSPECTION_REQUIRE([1.61.1])
 
 GLIB_REQUIREMENT="glib-2.0 >= glib_required_version"
 GOBJECT_REQUIREMENT="gobject-2.0 >= glib_required_version"
diff --git a/gi/object.cpp b/gi/object.cpp
index a28f4979..e79ba10e 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -641,8 +641,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) {
@@ -650,24 +653,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) {
             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;
             }
         }
@@ -678,14 +673,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;
 }
 
@@ -831,8 +823,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,


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