[gjs] arg: don't check manually for interface prerequisites
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] arg: don't check manually for interface prerequisites
- Date: Wed, 26 Feb 2014 00:56:21 +0000 (UTC)
commit 58ab20d8b8dea9365a9826b2f18e5167dc9a9201
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Mon Feb 24 13:42:21 2014 +0100
arg: don't check manually for interface prerequisites
g_type_is_a(interface, prerequisite) already does the expected thing,
we don't need a slow manual check.
Moreover, it's not documented, but add_prerequisite() always
resolves a GTypeInterface type into the instantiable prerequisites,
so g_type_interface_prerequisites() always returns instantiatable
types.
https://bugzilla.gnome.org/show_bug.cgi?id=725061
gi/arg.cpp | 50 ++++++++++----------------------------------------
1 files changed, 10 insertions(+), 40 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index c2373ca..90376e1 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -39,26 +39,6 @@
#include <util/log.h>
-static gboolean
-_gjs_gtype_interface_requires_object (GType interface_type)
-{
- guint i, n_prerequisites;
- GType *prerequisites = g_type_interface_prerequisites (interface_type,
- &n_prerequisites);
-
- for (i = 0; i < n_prerequisites; i++) {
- if (g_type_is_a (prerequisites[i], G_TYPE_INTERFACE)) {
- if (_gjs_gtype_interface_requires_object(prerequisites[i]))
- return TRUE;
- } else if (g_type_is_a (prerequisites[i], G_TYPE_OBJECT))
- return TRUE;
- }
-
- g_free (prerequisites);
-
- return FALSE;
-}
-
JSBool
_gjs_flags_value_is_valid(JSContext *context,
GType gtype,
@@ -2645,21 +2625,11 @@ gjs_value_from_g_argument (JSContext *context,
goto out;
}
-
- gtype_is_object = g_type_is_a(gtype, G_TYPE_OBJECT);
- gtype_is_interface = g_type_is_a(gtype, G_TYPE_INTERFACE);
- if (gtype_is_object || gtype_is_interface) {
- if (gtype_is_object || (gtype_is_interface && _gjs_gtype_interface_requires_object(gtype))) {
- JSObject *obj;
- obj = gjs_object_from_g_object(context, G_OBJECT(arg->v_pointer));
- if (obj)
- value = OBJECT_TO_JSVAL(obj);
- } else {
- JSObject *obj;
- obj = gjs_object_from_g_fundamental(context, (GIObjectInfo *)interface_info,
arg->v_pointer);
- if (obj)
- value = OBJECT_TO_JSVAL(obj);
- }
+ if (g_type_is_a(gtype, G_TYPE_OBJECT)) {
+ JSObject *obj;
+ obj = gjs_object_from_g_object(context, G_OBJECT(arg->v_pointer));
+ if (obj)
+ value = OBJECT_TO_JSVAL(obj);
} else if (g_type_is_a(gtype, G_TYPE_BOXED) ||
g_type_is_a(gtype, G_TYPE_ENUM) ||
g_type_is_a(gtype, G_TYPE_FLAGS)) {
@@ -2676,11 +2646,11 @@ gjs_value_from_g_argument (JSContext *context,
value = OBJECT_TO_JSVAL(obj);
} else if (gtype == G_TYPE_NONE) {
gjs_throw(context, "Unexpected unregistered type packing GArgument into jsval");
- } else if (G_TYPE_IS_INSTANTIATABLE(gtype)) {
- JSObject *obj;
- obj = gjs_object_from_g_fundamental(context, (GIObjectInfo *)interface_info,
arg->v_pointer);
- if (obj)
- value = OBJECT_TO_JSVAL(obj);
+ } else if (G_TYPE_IS_INSTANTIATABLE(gtype) || G_TYPE_IS_INTERFACE(gtype)) {
+ JSObject *obj;
+ obj = gjs_object_from_g_fundamental(context, (GIObjectInfo *)interface_info, arg->v_pointer);
+ if (obj)
+ value = OBJECT_TO_JSVAL(obj);
} else {
gjs_throw(context, "Unhandled GType %s packing GArgument into jsval",
g_type_name(gtype));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]