[gtk/optimize-precompile: 8/11] builder: Use a flexible array for attributes in precompile
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/optimize-precompile: 8/11] builder: Use a flexible array for attributes in precompile
- Date: Fri, 10 Dec 2021 19:48:10 +0000 (UTC)
commit 161a1d5b671ee4a0f492b2977506e396e34a5b81
Author: Garrett Regier <garrettregier gmail com>
Date: Tue Sep 21 15:26:45 2021 -0700
builder: Use a flexible array for attributes in precompile
gtk/gtkbuilderprecompile.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkbuilderprecompile.c b/gtk/gtkbuilderprecompile.c
index f9d216cfb6..d010657386 100644
--- a/gtk/gtkbuilderprecompile.c
+++ b/gtk/gtkbuilderprecompile.c
@@ -53,10 +53,10 @@ struct RecordDataElement {
RecordDataNode base;
RecordDataElement *parent;
+ GQueue children;
int n_attributes;
RecordDataString *name;
- RecordDataString **attributes;
- GQueue children;
+ RecordDataString *attributes[];
};
typedef struct {
@@ -90,15 +90,18 @@ record_data_node_new (RecordDataElement *parent,
static RecordDataElement *
record_data_element_new (RecordDataElement *parent,
- RecordDataString *name)
+ RecordDataString *name,
+ gsize n_attributes)
{
RecordDataElement *element;
element = record_data_node_new (parent,
RECORD_TYPE_ELEMENT,
- sizeof (RecordDataElement));
+ sizeof (RecordDataElement) +
+ sizeof (RecordDataString) * n_attributes);
element->parent = parent;
element->name = name;
+ element->n_attributes = n_attributes;
return element;
}
@@ -130,8 +133,8 @@ record_data_node_free (RecordDataNode *node)
for (l = element->children.head; l != NULL; l = l->next)
record_data_node_free (l->data);
- g_free (element->attributes);
- g_slice_free (RecordDataElement, element);
+ g_slice_free1 (sizeof (RecordDataElement) +
+ sizeof (RecordDataString) * element->n_attributes, element);
break;
case RECORD_TYPE_TEXT:
text = (RecordDataText *)node;
@@ -232,12 +235,9 @@ record_start_element (GMarkupParseContext *context,
int i;
name = record_data_string_lookup (data, element_name, -1);
- child = record_data_element_new (data->current, name);
+ child = record_data_element_new (data->current, name, n_attrs);
data->current = child;
- child->n_attributes = n_attrs;
- child->attributes = g_new (RecordDataString *, n_attrs * 2);
-
attr_names = &child->attributes[0];
attr_values = &child->attributes[n_attrs];
for (i = 0; i < n_attrs; i++)
@@ -420,7 +420,7 @@ _gtk_buildable_parser_precompile (const char *text,
data.strings = g_hash_table_new_full (record_data_string_hash, record_data_string_equal,
(GDestroyNotify)record_data_string_free, NULL);
data.chunks = g_string_chunk_new (512);
- data.root = record_data_element_new (NULL, NULL);
+ data.root = record_data_element_new (NULL, NULL, 0);
data.current = data.root;
ctx = g_markup_parse_context_new (&record_parser, G_MARKUP_TREAT_CDATA_AS_TEXT,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]