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




commit fcb6adaaaa66e859c8404807455c8f33c41ccf30
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 b75a0023a7..7c8dac9a5a 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 {
@@ -153,12 +155,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)
@@ -435,8 +431,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;
@@ -489,6 +484,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]