Add functions to intern strings.
authorMatthias Clasen <mclasen@redhat.com>
Wed, 31 Aug 2005 14:25:45 +0000 (14:25 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 31 Aug 2005 14:25:45 +0000 (14:25 +0000)
2005-08-31  Matthias Clasen  <mclasen@redhat.com>

* glib/glib.symbols:
* glib/gquark.h:
* glib/gdataset.c: Add functions to intern strings.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
docs/reference/ChangeLog
docs/reference/glib/glib-sections.txt
docs/reference/glib/tmpl/quarks.sgml
glib/gdataset.c
glib/glib.symbols
glib/gquark.h

index 15caea5..f5c482a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-08-31  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/glib.symbols: 
+       * glib/gquark.h: 
+       * glib/gdataset.c: 
+
 2005-08-28  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/giochannel.c: Unify some near-duplicate strings. (#314654,
index 15caea5..f5c482a 100644 (file)
@@ -1,3 +1,9 @@
+2005-08-31  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/glib.symbols: 
+       * glib/gquark.h: 
+       * glib/gdataset.c: 
+
 2005-08-28  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/giochannel.c: Unify some near-duplicate strings. (#314654,
index 15caea5..f5c482a 100644 (file)
@@ -1,3 +1,9 @@
+2005-08-31  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/glib.symbols: 
+       * glib/gquark.h: 
+       * glib/gdataset.c: 
+
 2005-08-28  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/giochannel.c: Unify some near-duplicate strings. (#314654,
index 2d14ed2..5ffbd31 100644 (file)
@@ -1,3 +1,8 @@
+2005-08-31  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/tmpl/quarks.sgml: 
+       * glib/glib-sections.txt: Add string interning functions.
+
 2005-08-30  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/tmpl/arrays.sgml: 
index 79ed478..80cd93d 100644 (file)
@@ -1958,7 +1958,8 @@ g_quark_from_string
 g_quark_from_static_string
 g_quark_to_string
 g_quark_try_string
-
+g_intern_string
+g_intern_static_string
 </SECTION>
 
 <SECTION>
index 7a8159e..72bc1a7 100644 (file)
@@ -25,6 +25,13 @@ To find the string corresponding to a given #GQuark, use g_quark_to_string().
 <para>
 To find the #GQuark corresponding to a given string, use g_quark_try_string().
 </para>
+<para>
+Another use for the string pool maintained for the quark functions is string
+interning, using g_intern_string() or g_intern_static_string(). An interned string 
+is a canonical representation for a string. One important advantage of interned strings 
+is that they can be compared for equality by a simple pointer comparision, rather than 
+using strcmp(). 
+</para>
 
 <!-- ##### SECTION See_Also ##### -->
 <para>
index 45d3ba6..37c3466 100644 (file)
@@ -711,5 +711,43 @@ g_quark_new (gchar *string)
   return quark;
 }
 
+/**
+ * g_intern_string:
+ * @string: a string
+ * 
+ * Returns a canonical representation for @string. Interned strings can
+ * be compared for equality by comparing the pointers, instead of using strcmp().
+ * 
+ * Returns: a canonical representation for the string
+ *
+ * Since: 2.10
+ */
+G_CONST_RETURN gchar*
+g_intern_string (const gchar *string)
+{
+   return string ? g_quark_to_string (g_quark_from_string (string)) : NULL;
+}
+
+/**
+ * g_intern_static_string:
+ * @string: a static string
+ * 
+ * Returns a canonical representation for @string. Interned strings can
+ * be compared for equality by comparing the pointers, instead of using strcmp().
+ * g_intern_static_string() does not copy the string, therefore @string must
+ * not be freed or modified. 
+ * 
+ * Returns: a canonical representation for the string
+ *
+ * Since: 2.10
+ */
+G_CONST_RETURN gchar*
+g_intern_static_string (const gchar *string)
+{
+   return string ? g_quark_to_string (g_quark_from_static_string (string)) : NULL;
+}
+
+
+
 #define __G_DATASET_C__
 #include "galiasdef.c"
index bb205c6..8170aaf 100644 (file)
@@ -165,10 +165,17 @@ g_dataset_foreach
 g_dataset_id_get_data
 g_dataset_id_remove_no_notify
 g_dataset_id_set_data_full
+#endif
+#endif
+
+#if IN_HEADER(__G_QUARK_H__)
+#if IN_FILE(__G_DATASET_C__)
 g_quark_from_static_string
 g_quark_from_string
 g_quark_to_string G_GNUC_CONST
 g_quark_try_string
+g_intern_string
+g_intern_static_string
 #endif
 #endif
 
index 6b96dcf..fc3006f 100644 (file)
@@ -40,6 +40,10 @@ GQuark                g_quark_from_static_string (const gchar *string);
 GQuark                g_quark_from_string        (const gchar *string);
 G_CONST_RETURN gchar* g_quark_to_string          (GQuark       quark) G_GNUC_CONST;
 
+G_CONST_RETURN gchar* g_intern_string            (const gchar *string);
+G_CONST_RETURN gchar* g_intern_static_string     (const gchar *string);
+
+
 G_END_DECLS
 
 #endif /* __G_QUARK_H__ */