mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-10-28 18:16:16 +01:00
refstring: add GEqualFunc for ref-counted strings
This is the same as g_str_equal() except that it will first check the string length for equality before dereferencing string contents.
This commit is contained in:
parent
73f5ca5763
commit
3bb903d35d
@ -234,3 +234,26 @@ g_ref_string_length (char *str)
|
||||
|
||||
return g_atomic_rc_box_get_size (str) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_ref_string_equal:
|
||||
* @str1: a reference counted string
|
||||
* @str2: a reference counted string
|
||||
*
|
||||
* Compares two ref-counted strings for byte-by-byte equality
|
||||
* and returns `TRUE` if they are equal. It can be passed to
|
||||
* `g_hash_table_new()` as the `@key_equal_func` parameter.
|
||||
*
|
||||
* Returns: `TRUE` if the strings are equal, otherwise `FALSE`
|
||||
*
|
||||
* Since: 2.82
|
||||
*/
|
||||
gboolean
|
||||
g_ref_string_equal (char *str1,
|
||||
char *str2)
|
||||
{
|
||||
if (g_atomic_rc_box_get_size (str1) != g_atomic_rc_box_get_size (str2))
|
||||
return FALSE;
|
||||
|
||||
return strcmp (str1, str2) == 0;
|
||||
}
|
||||
|
@ -56,4 +56,8 @@ gsize g_ref_string_length (char *str);
|
||||
*/
|
||||
typedef char GRefString;
|
||||
|
||||
GLIB_AVAILABLE_IN_2_82
|
||||
gboolean g_ref_string_equal (char *str1,
|
||||
char *str2);
|
||||
|
||||
G_END_DECLS
|
||||
|
Loading…
Reference in New Issue
Block a user