mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-10 23:00:07 +02:00
Add functions to intern strings.
2005-08-31 Matthias Clasen <mclasen@redhat.com> * glib/glib.symbols: * glib/gquark.h: * glib/gdataset.c: Add functions to intern strings.
This commit is contained in:
parent
9b9ec85b28
commit
70af0de0ef
@ -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>
|
2005-08-28 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c: Unify some near-duplicate strings. (#314654,
|
* glib/giochannel.c: Unify some near-duplicate strings. (#314654,
|
||||||
|
@ -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>
|
2005-08-28 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c: Unify some near-duplicate strings. (#314654,
|
* glib/giochannel.c: Unify some near-duplicate strings. (#314654,
|
||||||
|
@ -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>
|
2005-08-28 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c: Unify some near-duplicate strings. (#314654,
|
* glib/giochannel.c: Unify some near-duplicate strings. (#314654,
|
||||||
|
@ -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>
|
2005-08-30 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/tmpl/arrays.sgml:
|
* glib/tmpl/arrays.sgml:
|
||||||
|
@ -1958,7 +1958,8 @@ g_quark_from_string
|
|||||||
g_quark_from_static_string
|
g_quark_from_static_string
|
||||||
g_quark_to_string
|
g_quark_to_string
|
||||||
g_quark_try_string
|
g_quark_try_string
|
||||||
|
g_intern_string
|
||||||
|
g_intern_static_string
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
|
@ -25,6 +25,13 @@ To find the string corresponding to a given #GQuark, use g_quark_to_string().
|
|||||||
<para>
|
<para>
|
||||||
To find the #GQuark corresponding to a given string, use g_quark_try_string().
|
To find the #GQuark corresponding to a given string, use g_quark_try_string().
|
||||||
</para>
|
</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 ##### -->
|
<!-- ##### SECTION See_Also ##### -->
|
||||||
<para>
|
<para>
|
||||||
|
@ -711,5 +711,43 @@ g_quark_new (gchar *string)
|
|||||||
return quark;
|
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__
|
#define __G_DATASET_C__
|
||||||
#include "galiasdef.c"
|
#include "galiasdef.c"
|
||||||
|
@ -165,10 +165,17 @@ g_dataset_foreach
|
|||||||
g_dataset_id_get_data
|
g_dataset_id_get_data
|
||||||
g_dataset_id_remove_no_notify
|
g_dataset_id_remove_no_notify
|
||||||
g_dataset_id_set_data_full
|
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_static_string
|
||||||
g_quark_from_string
|
g_quark_from_string
|
||||||
g_quark_to_string G_GNUC_CONST
|
g_quark_to_string G_GNUC_CONST
|
||||||
g_quark_try_string
|
g_quark_try_string
|
||||||
|
g_intern_string
|
||||||
|
g_intern_static_string
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -40,6 +40,10 @@ GQuark g_quark_from_static_string (const gchar *string);
|
|||||||
GQuark g_quark_from_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_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
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __G_QUARK_H__ */
|
#endif /* __G_QUARK_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user