[gtk/optimize-precompile: 10/11] builder: Remove root special case from precompile




commit a868f280c29df7a371fbd0f5b8c04abea5d1c0ca
Author: Garrett Regier <garrettregier gmail com>
Date:   Thu Sep 23 15:21:53 2021 -0700

    builder: Remove root special case from precompile

 gtk/gtkbuilderprecompile.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkbuilderprecompile.c b/gtk/gtkbuilderprecompile.c
index 93e97c1336..6551eaa640 100644
--- a/gtk/gtkbuilderprecompile.c
+++ b/gtk/gtkbuilderprecompile.c
@@ -369,27 +369,22 @@ marshal_tree (GString        *marshaled,
     case RECORD_TYPE_ELEMENT:
       element = (RecordDataElement *)node;
 
-      /* Special case the root */
-      if (element->parent != NULL)
+      marshal_uint32 (marshaled, RECORD_TYPE_ELEMENT);
+      marshal_uint32 (marshaled, element->name->offset);
+      marshal_uint32 (marshaled, element->n_attributes);
+
+      attr_names = &element->attributes[0];
+      attr_values = &element->attributes[element->n_attributes];
+      for (i = 0; i < element->n_attributes; i++)
         {
-          marshal_uint32 (marshaled, RECORD_TYPE_ELEMENT);
-          marshal_uint32 (marshaled, element->name->offset);
-          marshal_uint32 (marshaled, element->n_attributes);
-
-          attr_names = &element->attributes[0];
-          attr_values = &element->attributes[element->n_attributes];
-          for (i = 0; i < element->n_attributes; i++)
-            {
-              marshal_uint32 (marshaled, attr_names[i]->offset);
-              marshal_uint32 (marshaled, attr_values[i]->offset);
-            }
+          marshal_uint32 (marshaled, attr_names[i]->offset);
+          marshal_uint32 (marshaled, attr_values[i]->offset);
         }
 
       for (l = element->children.head; l != NULL; l = l->next)
         marshal_tree (marshaled, l->data);
 
-      if (element->parent != NULL)
-        marshal_uint32 (marshaled, RECORD_TYPE_END_ELEMENT);
+      marshal_uint32 (marshaled, RECORD_TYPE_END_ELEMENT);
       break;
     case RECORD_TYPE_TEXT:
       text = (RecordDataText *)node;
@@ -402,6 +397,17 @@ marshal_tree (GString        *marshaled,
     }
 }
 
+static void
+marshal_root (GString        *marshaled,
+              RecordDataNode *node)
+{
+  GList *l;
+  RecordDataElement *element = (RecordDataElement *)node;
+
+  for (l = element->children.head; l != NULL; l = l->next)
+    marshal_tree (marshaled, l->data);
+}
+
 /**
  * _gtk_buildable_parser_precompile:
  * @text: chunk of text to parse
@@ -476,7 +482,7 @@ _gtk_buildable_parser_precompile (const char  *text,
       g_string_append_len (marshaled, s->string, s->len + 1);
     }
 
-  marshal_tree (marshaled, &data.root->base);
+  marshal_root (marshaled, &data.root->base);
 
   record_data_node_free (&data.root->base);
   g_string_chunk_free (data.chunks);


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