[gtk/wip/baedert/for-master] builderparser: Keep properties in a GPtrArray



commit ad1957b257b6b0a990d0183674b4b65dd5b7d7cc
Author: Timm Bäder <mail baedert org>
Date:   Wed Jan 6 19:07:44 2021 +0100

    builderparser: Keep properties in a GPtrArray

 gtk/gtkbuilder.c        | 10 ++++++----
 gtk/gtkbuilderparser.c  | 21 ++++++++++++---------
 gtk/gtkbuilderprivate.h |  4 +++-
 3 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index ef1237fccc..dcd804e180 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -527,19 +527,21 @@ static void
 gtk_builder_get_parameters (GtkBuilder         *builder,
                             GType               object_type,
                             const char         *object_name,
-                            GSList             *properties,
+                            GPtrArray          *properties,
                             GParamFlags         filter_flags,
                             ObjectProperties   *parameters,
                             ObjectProperties   *filtered_parameters)
 {
   GtkBuilderPrivate *priv = gtk_builder_get_instance_private (builder);
-  GSList *l;
   DelayedProperty *property;
   GError *error = NULL;
 
-  for (l = properties; l; l = l->next)
+  if (!properties)
+    return;
+
+  for (guint i = 0; i < properties->len; i++)
     {
-      PropertyInfo *prop = (PropertyInfo*)l->data;
+      PropertyInfo *prop = g_ptr_array_index (properties, i);
       const char *property_name = g_intern_string (prop->pspec->name);
       GValue property_value = G_VALUE_INIT;
 
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index b22cb1dfe5..3c969fab5d 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -176,7 +176,7 @@ gtk_buildable_parse_context_free (GtkBuildableParseContext *context)
 
   g_ptr_array_unref (context->tag_stack);
 }
-
+#include <valgrind/callgrind.h>
 static gboolean
 gtk_buildable_parse_context_parse (GtkBuildableParseContext *context,
                                    const char           *text,
@@ -191,11 +191,13 @@ gtk_buildable_parse_context_parse (GtkBuildableParseContext *context,
     }
   else
     {
+    CALLGRIND_START_INSTRUMENTATION;
       context->ctx = g_markup_parse_context_new (context->internal_callbacks,
                                                  G_MARKUP_TREAT_CDATA_AS_TEXT,
                                                  context, NULL);
       res = g_markup_parse_context_parse (context->ctx, text, text_len, error);
       g_markup_parse_context_free  (context->ctx);
+      CALLGRIND_STOP_INSTRUMENTATION;
     }
 
   return res;
@@ -471,8 +473,6 @@ builder_construct (ParserData  *data,
   if (object_info->object && object_info->applied_properties)
     return object_info->object;
 
-  object_info->properties = g_slist_reverse (object_info->properties);
-
   if (object_info->object == NULL)
     {
       object = _gtk_builder_construct (data->builder, object_info, error);
@@ -800,18 +800,19 @@ free_object_info (ObjectInfo *info)
   /* Do not free the signal items, which GtkBuilder takes ownership of */
   g_type_class_unref (info->oclass);
   g_slist_free (info->signals);
-  g_slist_free_full (info->properties, (GDestroyNotify)free_property_info);
+  if (info->properties)
+    g_ptr_array_free (info->properties, TRUE);
   g_free (info->constructor);
   g_free (info->id);
   g_slice_free (ObjectInfo, info);
 }
 
 static void
-parse_child (ParserData   *data,
-             const char   *element_name,
+parse_child (ParserData  *data,
+             const char  *element_name,
              const char **names,
              const char **values,
-             GError      **error)
+             GError     **error)
 
 {
   ObjectInfo* object_info;
@@ -1707,7 +1708,6 @@ parse_custom (GtkBuildableParseContext  *context,
       ObjectInfo* object_info = (ObjectInfo*)parent_info;
       if (!object_info->object)
         {
-          object_info->properties = g_slist_reverse (object_info->properties);
           object_info->object = _gtk_builder_construct (data->builder,
                                                         object_info,
                                                         error);
@@ -1885,7 +1885,10 @@ end_element (GtkBuildableParseContext  *context,
               g_string_assign (prop_info->text, translated);
             }
 
-          object_info->properties = g_slist_prepend (object_info->properties, prop_info);
+          if (G_UNLIKELY (!object_info->properties))
+            object_info->properties = g_ptr_array_new_with_free_func ((GDestroyNotify)free_property_info);
+
+          g_ptr_array_add (object_info->properties, prop_info);
         }
       else
         g_assert_not_reached ();
diff --git a/gtk/gtkbuilderprivate.h b/gtk/gtkbuilderprivate.h
index 74c688b2de..f86aaea629 100644
--- a/gtk/gtkbuilderprivate.h
+++ b/gtk/gtkbuilderprivate.h
@@ -46,9 +46,11 @@ typedef struct {
   GObjectClass *oclass;
   char *id;
   char *constructor;
-  GSList *properties;
+
+  GPtrArray *properties;
   GSList *signals;
   GSList *bindings;
+
   GObject *object;
   CommonInfo *parent;
   gboolean applied_properties;


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