[gtk/optimize-precompile: 9/11] builder: Avoid g_hash_table_get_values() in precompile
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/optimize-precompile: 9/11] builder: Avoid g_hash_table_get_values() in precompile
- Date: Fri, 10 Dec 2021 19:48:12 +0000 (UTC)
commit 77385390bbe0c2ac875868775222d2eaf964957e
Author: Garrett Regier <garrettregier gmail com>
Date: Tue Sep 21 18:01:54 2021 -0700
builder: Avoid g_hash_table_get_values() in precompile
Embed the GList link in the RecordDataString.
gtk/gtkbuilderprecompile.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkbuilderprecompile.c b/gtk/gtkbuilderprecompile.c
index d010657386..93e97c1336 100644
--- a/gtk/gtkbuilderprecompile.c
+++ b/gtk/gtkbuilderprecompile.c
@@ -40,6 +40,7 @@ typedef struct {
int offset;
int text_offset;
gboolean include_len;
+ GList link;
} RecordDataString;
typedef struct {
@@ -68,6 +69,7 @@ typedef struct {
typedef struct {
GHashTable *strings;
GStringChunk *chunks;
+ GQueue string_list;
RecordDataElement *root;
RecordDataElement *current;
} RecordData;
@@ -179,7 +181,8 @@ record_data_string_hash (gconstpointer _a)
static int
record_data_string_compare (gconstpointer _a,
- gconstpointer _b)
+ gconstpointer _b,
+ gpointer user_data)
{
const RecordDataString *a = _a;
const RecordDataString *b = _b;
@@ -215,8 +218,12 @@ record_data_string_lookup (RecordData *data,
s->len = len;
s->count = 1;
s->include_len = include_len;
+ s->link.data = s;
+ s->link.next = NULL;
+ s->link.prev = NULL;
g_hash_table_add (data->strings, s);
+ g_queue_push_tail_link (&data->string_list, &s->link);
return s;
}
@@ -413,7 +420,7 @@ _gtk_buildable_parser_precompile (const char *text,
{
GMarkupParseContext *ctx;
RecordData data = { 0 };
- GList *string_table, *l;
+ GList *l;
GString *marshaled;
int offset;
@@ -437,11 +444,10 @@ _gtk_buildable_parser_precompile (const char *text,
g_markup_parse_context_free (ctx);
- string_table = g_hash_table_get_values (data.strings);
- string_table = g_list_sort (string_table, record_data_string_compare);
+ g_queue_sort (&data.string_list, record_data_string_compare, NULL);
offset = 0;
- for (l = string_table; l != NULL; l = l->next)
+ for (l = data.string_list.head; l != NULL; l = l->next)
{
RecordDataString *s = l->data;
@@ -460,7 +466,7 @@ _gtk_buildable_parser_precompile (const char *text,
g_string_append_len (marshaled, "GBU\0", 4);
marshal_uint32 (marshaled, offset);
- for (l = string_table; l != NULL; l = l->next)
+ for (l = data.string_list.head; l != NULL; l = l->next)
{
RecordDataString *s = l->data;
@@ -470,8 +476,6 @@ _gtk_buildable_parser_precompile (const char *text,
g_string_append_len (marshaled, s->string, s->len + 1);
}
- g_list_free (string_table);
-
marshal_tree (marshaled, &data.root->base);
record_data_node_free (&data.root->base);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]