return quark;
}
+#define QUARK_STRING_BLOCK_SIZE (4096 - sizeof (gsize))
+static char *quark_block = NULL;
+static int quark_block_offset = 0;
+
+/* HOLDS: g_quark_global_lock */
+static char *
+quark_strdup(const gchar *string)
+{
+ gchar *copy;
+ gsize len;
+
+ len = strlen (string) + 1;
+
+ /* For strings longer than half the block size, fall back
+ to strdup so that we fill our blocks at least 50%. */
+ if (len > QUARK_STRING_BLOCK_SIZE / 2)
+ return g_strdup (string);
+
+ if (quark_block == NULL ||
+ QUARK_STRING_BLOCK_SIZE - quark_block_offset < len)
+ {
+ quark_block = g_malloc (QUARK_STRING_BLOCK_SIZE);
+ quark_block_offset = 0;
+ }
+
+ copy = quark_block + quark_block_offset;
+ memcpy (copy, string, len);
+ quark_block_offset += len;
+
+ return copy;
+}
+
/* HOLDS: g_quark_global_lock */
static inline GQuark
g_quark_from_string_internal (const gchar *string,
quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string));
if (!quark)
- quark = g_quark_new (duplicate ? g_strdup (string) : (gchar *)string);
-
+ quark = g_quark_new (duplicate ? quark_strdup (string) : (gchar *)string);
+
return quark;
}