[libpeas] Reduce the number of allocations in calling methods via GI



commit dc51fffb98e716904684902d6e7325e3975f32f4
Author: Garrett Regier <alias301 gmail com>
Date:   Sun Dec 19 15:52:28 2010 -0800

    Reduce the number of allocations in calling methods via GI

 libpeas/peas-extension-subclasses.c |   34 +++++++++++++---------------------
 libpeas/peas-extension.c            |    7 +++----
 libpeas/peas-introspection.c        |   31 ++++++++++++-------------------
 loaders/seed/peas-extension-seed.c  |    8 ++++----
 4 files changed, 32 insertions(+), 48 deletions(-)
---
diff --git a/libpeas/peas-extension-subclasses.c b/libpeas/peas-extension-subclasses.c
index 18140f4..f212148 100644
--- a/libpeas/peas-extension-subclasses.c
+++ b/libpeas/peas-extension-subclasses.c
@@ -56,9 +56,9 @@ handle_method_impl (ffi_cif  *cif,
                     gpointer  data)
 {
   MethodImpl *impl = (MethodImpl *) data;
-  GIArgInfo *arg_info;
-  GITypeInfo *type_info;
-  GITypeInfo *return_type_info;
+  GIArgInfo arg_info;
+  GITypeInfo type_info;
+  GITypeInfo return_type_info;
   gint n_args, i;
   PeasExtension *instance;
   GIArgument *arguments;
@@ -73,13 +73,10 @@ handle_method_impl (ffi_cif  *cif,
 
   for (i = 1; i < n_args; i++)
     {
-      arg_info = g_callable_info_get_arg (impl->info, i);
-      type_info = g_arg_info_get_type (arg_info);
-
-      peas_gi_pointer_to_argument (type_info, args[i], &arguments[i-1]);
+      g_callable_info_load_arg (impl->info, i, &arg_info);
+      g_arg_info_load_type (&arg_info, &type_info);
 
-      g_base_info_unref (type_info);
-      g_base_info_unref (arg_info);
+      peas_gi_pointer_to_argument (&type_info, args[i], &arguments[i-1]);
     }
 
   peas_extension_callv (instance, impl->method_name, arguments, &return_value);
@@ -88,25 +85,20 @@ handle_method_impl (ffi_cif  *cif,
     {
       GIDirection direction;
 
-      arg_info = g_callable_info_get_arg (impl->info, i);
-      direction = g_arg_info_get_direction (arg_info);
+      g_callable_info_load_arg (impl->info, i, &arg_info);
+      direction = g_arg_info_get_direction (&arg_info);
 
       if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT)
         {
-          type_info = g_arg_info_get_type (arg_info);
-          peas_gi_argument_to_pointer (type_info, &arguments[i-1], args[i]);
-          g_base_info_unref (type_info);
+          g_arg_info_load_type (&arg_info, &type_info);
+          peas_gi_argument_to_pointer (&type_info, &arguments[i-1], args[i]);
         }
-
-      g_base_info_unref (arg_info);
     }
 
-  return_type_info = g_callable_info_get_return_type (impl->info);
-
-  if (g_type_info_get_tag (return_type_info) != GI_TYPE_TAG_VOID)
-    peas_gi_argument_to_pointer (return_type_info, &return_value, result);
+  g_callable_info_load_return_type (impl->info, &return_type_info);
 
-  g_base_info_unref (return_type_info);
+  if (g_type_info_get_tag (&return_type_info) != GI_TYPE_TAG_VOID)
+    peas_gi_argument_to_pointer (&return_type_info, &return_value, result);
 }
 
 static void
diff --git a/libpeas/peas-extension.c b/libpeas/peas-extension.c
index 21cd538..261f56d 100644
--- a/libpeas/peas-extension.c
+++ b/libpeas/peas-extension.c
@@ -212,7 +212,7 @@ peas_extension_call_valist (PeasExtension *exten,
                             va_list        args)
 {
   GICallableInfo *callable_info;
-  GITypeInfo *retval_info;
+  GITypeInfo retval_info;
   GIArgument *gargs;
   GIArgument retval;
   gpointer retval_ptr;
@@ -234,9 +234,8 @@ peas_extension_call_valist (PeasExtension *exten,
 
   if (retval_ptr != NULL)
     {
-      retval_info = g_callable_info_get_return_type (callable_info);
-      peas_gi_argument_to_pointer (retval_info, &retval, retval_ptr);
-      g_base_info_unref ((GIBaseInfo *) retval_info);
+      g_callable_info_load_return_type (callable_info, &retval_info);
+      peas_gi_argument_to_pointer (&retval_info, &retval, retval_ptr);
     }
 
   g_base_info_unref ((GIBaseInfo *) callable_info);
diff --git a/libpeas/peas-introspection.c b/libpeas/peas-introspection.c
index 705c21a..25c9849 100644
--- a/libpeas/peas-introspection.c
+++ b/libpeas/peas-introspection.c
@@ -32,9 +32,9 @@ peas_gi_valist_to_arguments (GICallableInfo *callable_info,
                              gpointer       *return_value)
 {
   gint i, n_args;
-  GIArgInfo *arg_info;
-  GITypeInfo *arg_type_info;
-  GITypeInfo *retval_info;
+  GIArgInfo arg_info;
+  GITypeInfo arg_type_info;
+  GITypeInfo retval_info;
   GIArgument *cur_arg;
 
   g_return_if_fail (callable_info != NULL);
@@ -43,11 +43,11 @@ peas_gi_valist_to_arguments (GICallableInfo *callable_info,
 
   for (i = 0; i < n_args; i++)
     {
-      arg_info = g_callable_info_get_arg (callable_info, i);
-      arg_type_info = g_arg_info_get_type (arg_info);
+      g_callable_info_load_arg (callable_info, i, &arg_info);
+      g_arg_info_load_type (&arg_info, &arg_type_info);
       cur_arg = &arguments[i];
 
-      switch (g_arg_info_get_direction (arg_info))
+      switch (g_arg_info_get_direction (&arg_info))
         {
         case GI_DIRECTION_IN:
           {
@@ -55,7 +55,7 @@ peas_gi_valist_to_arguments (GICallableInfo *callable_info,
              *  - int8, uint8, int16, uint16, short and ushort are promoted to int when passed through '...'
              *  - float is promoted to double when passed through '...'
              */
-            switch (g_type_info_get_tag (arg_type_info))
+            switch (g_type_info_get_tag (&arg_type_info))
               {
               case GI_TYPE_TAG_VOID:
               case GI_TYPE_TAG_BOOLEAN:
@@ -120,21 +120,16 @@ peas_gi_valist_to_arguments (GICallableInfo *callable_info,
           cur_arg->v_pointer = va_arg (va_args, gpointer);
           break;
         }
-
-      g_base_info_unref ((GIBaseInfo *) arg_type_info);
-      g_base_info_unref ((GIBaseInfo *) arg_info);
     }
 
   if (return_value != NULL)
     {
-      retval_info = g_callable_info_get_return_type (callable_info);
+      g_callable_info_load_return_type (callable_info, &retval_info);
 
-      if (g_type_info_get_tag (retval_info) != GI_TYPE_TAG_VOID)
+      if (g_type_info_get_tag (&retval_info) != GI_TYPE_TAG_VOID)
         *return_value = va_arg (va_args, gpointer);
       else
         *return_value = NULL;
-
-      g_base_info_unref ((GIBaseInfo *) retval_info);
     }
 }
 
@@ -147,7 +142,7 @@ peas_gi_split_in_and_out_arguments (GICallableInfo *callable_info,
                                     guint          *n_out_args)
 {
   gint n_args, i;
-  GIArgInfo *arg_info;
+  GIArgInfo arg_info;
 
   g_return_if_fail (callable_info != NULL);
 
@@ -155,9 +150,9 @@ peas_gi_split_in_and_out_arguments (GICallableInfo *callable_info,
 
   for (i = 0; i < n_args; i++)
     {
-      arg_info = g_callable_info_get_arg (callable_info, i);
+      g_callable_info_load_arg (callable_info, i, &arg_info);
 
-      switch (g_arg_info_get_direction (arg_info))
+      switch (g_arg_info_get_direction (&arg_info))
         {
         case GI_DIRECTION_IN:
           in_args[(*n_in_args)++] = args[i];
@@ -170,8 +165,6 @@ peas_gi_split_in_and_out_arguments (GICallableInfo *callable_info,
           out_args[(*n_out_args)++] = args[i];
           break;
         }
-
-      g_base_info_unref ((GIBaseInfo *) arg_info);
     }
 }
 
diff --git a/loaders/seed/peas-extension-seed.c b/loaders/seed/peas-extension-seed.c
index ab8e999..870f3db 100644
--- a/loaders/seed/peas-extension-seed.c
+++ b/loaders/seed/peas-extension-seed.c
@@ -295,13 +295,13 @@ peas_extension_seed_call (PeasExtension *exten,
   /* Handle the other arguments */
   for (i = 0; i < n_args && exc == NULL; i++)
     {
-      GIArgInfo *arg_info;
+      GIArgInfo arg_info;
       GITypeInfo *arg_type_info;
 
-      arg_info = g_callable_info_get_arg (func_info, i);
-      arg_type_info = g_arg_info_get_type (arg_info);
+      g_callable_info_load_arg (func_info, i, &arg_info);
+      arg_type_info = g_arg_info_load_type (&arg_info, &arg_type_info);
 
-      switch (g_arg_info_get_direction (arg_info))
+      switch (g_arg_info_get_direction (&arg_info))
         {
         case GI_DIRECTION_IN:
           js_in_args[n_in_args++] = get_argument (sexten->js_context,



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