[gtk/optimize-precompile: 11/11] builder: Use g_slice_free_chain() for strings in precompile




commit 69e258d5eeb67f85f1f57a290303dc0ee54f31e6
Author: Garrett Regier <garrettregier gmail com>
Date:   Thu Sep 23 15:26:56 2021 -0700

    builder: Use g_slice_free_chain() for strings in precompile

 gtk/gtkbuilderprecompile.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkbuilderprecompile.c b/gtk/gtkbuilderprecompile.c
index 6551eaa640..5a42085d07 100644
--- a/gtk/gtkbuilderprecompile.c
+++ b/gtk/gtkbuilderprecompile.c
@@ -34,13 +34,15 @@ typedef enum
 
 /* All strings are owned by the string chunk */
 typedef struct {
+  /* Must be first for g_slice_free_chain() */
+  GList link;
+
   const char *string;
   int len;
   int count;
   int offset;
   int text_offset;
   gboolean include_len;
-  GList link;
 } RecordDataString;
 
 typedef struct {
@@ -148,12 +150,6 @@ record_data_node_free (RecordDataNode *node)
     }
 }
 
-static void
-record_data_string_free (RecordDataString *s)
-{
-  g_slice_free (RecordDataString, s);
-}
-
 static gboolean
 record_data_string_equal (gconstpointer _a,
                           gconstpointer _b)
@@ -430,8 +426,7 @@ _gtk_buildable_parser_precompile (const char  *text,
   GString *marshaled;
   int offset;
 
-  data.strings = g_hash_table_new_full (record_data_string_hash, record_data_string_equal,
-                                        (GDestroyNotify)record_data_string_free, NULL);
+  data.strings = g_hash_table_new (record_data_string_hash, record_data_string_equal);
   data.chunks = g_string_chunk_new (512);
   data.root = record_data_element_new (NULL, NULL, 0);
   data.current = data.root;
@@ -484,6 +479,9 @@ _gtk_buildable_parser_precompile (const char  *text,
 
   marshal_root (marshaled, &data.root->base);
 
+  g_slice_free_chain (RecordDataString,
+                      (RecordDataString *)data.string_list.head,
+                      link.next);
   record_data_node_free (&data.root->base);
   g_string_chunk_free (data.chunks);
   g_hash_table_destroy (data.strings);


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