summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2015-09-11 23:59:27 -0400
committerMatthias Clasen <mclasen@redhat.com>2015-09-12 11:13:45 -0400
commit2fe992b099bfd3fb121a71b7af43e116b2142b5d (patch)
tree1c0b4afc9f39614056cb8d5f39ce29e484a31ac1
parent627854fee1fde93e01f27655b00a9082348ee15f (diff)
downloadglib-2fe992b099bfd3fb121a71b7af43e116b2142b5d.tar.gz
Move quark initialization to a constructor
This removes a branch from the very frequently called quark functions.
-rw-r--r--glib/glib-init.c1
-rw-r--r--glib/glib-init.h2
-rw-r--r--glib/gquark.c26
3 files changed, 17 insertions, 12 deletions
diff --git a/glib/glib-init.c b/glib/glib-init.c
index 24efe9dc1..e7002e65c 100644
--- a/glib/glib-init.c
+++ b/glib/glib-init.c
@@ -233,6 +233,7 @@ glib_init (void)
{
g_messages_prefixed_init ();
g_debug_init ();
+ g_quark_init ();
}
#if defined (G_OS_WIN32)
diff --git a/glib/glib-init.h b/glib/glib-init.h
index de6be78c7..b56f7e205 100644
--- a/glib/glib-init.h
+++ b/glib/glib-init.h
@@ -25,6 +25,8 @@
extern GLogLevelFlags g_log_always_fatal;
extern GLogLevelFlags g_log_msg_prefix;
+void g_quark_init (void);
+
#ifdef G_OS_WIN32
#include <windows.h>
diff --git a/glib/gquark.c b/glib/gquark.c
index d6205332c..9e51a92ff 100644
--- a/glib/gquark.c
+++ b/glib/gquark.c
@@ -40,6 +40,7 @@
#include "gthread.h"
#include "gtestutils.h"
#include "glib_trace.h"
+#include "glib-init.h"
#define QUARK_BLOCK_SIZE 2048
#define QUARK_STRING_BLOCK_SIZE (4096 - sizeof (gsize))
@@ -53,6 +54,16 @@ static gint quark_seq_id = 0;
static gchar *quark_block = NULL;
static gint quark_block_offset = 0;
+void
+g_quark_init (void)
+{
+ g_assert (quark_seq_id == 0);
+ quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
+ quarks = g_new (gchar*, QUARK_BLOCK_SIZE);
+ quarks[0] = NULL;
+ quark_seq_id = 1;
+}
+
/**
* SECTION:quarks
* @title: Quarks
@@ -127,10 +138,9 @@ g_quark_try_string (const gchar *string)
return 0;
G_LOCK (quark_global);
- if (quark_ht)
- quark = GPOINTER_TO_UINT (g_hash_table_lookup (quark_ht, string));
+ quark = GPOINTER_TO_UINT (g_hash_table_lookup (quark_ht, string));
G_UNLOCK (quark_global);
-
+
return quark;
}
@@ -169,8 +179,7 @@ quark_from_string (const gchar *string,
{
GQuark quark = 0;
- if (quark_ht)
- quark = GPOINTER_TO_UINT (g_hash_table_lookup (quark_ht, string));
+ quark = GPOINTER_TO_UINT (g_hash_table_lookup (quark_ht, string));
if (!quark)
{
@@ -283,13 +292,6 @@ quark_new (gchar *string)
*/
g_atomic_pointer_set (&quarks, quarks_new);
}
- if (!quark_ht)
- {
- g_assert (quark_seq_id == 0);
- quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
- quarks[quark_seq_id] = NULL;
- g_atomic_int_inc (&quark_seq_id);
- }
quark = quark_seq_id;
g_atomic_pointer_set (&quarks[quark], string);