diff options
author | rbuj <[email protected]> | 2019-03-05 19:23:42 +0100 |
---|---|---|
committer | ZenWalker <[email protected]> | 2019-03-29 16:31:09 +0100 |
commit | 8f568265bf65f4c7bdc19738f91b4e98ed826394 (patch) | |
tree | 0411fe29c22fe69e644e1c3242d22b39327b89c8 /eel | |
parent | 26800580d62402e4b3390743205fefe2732ac394 (diff) | |
download | caja-8f568265bf65f4c7bdc19738f91b4e98ed826394.tar.bz2 caja-8f568265bf65f4c7bdc19738f91b4e98ed826394.tar.xz |
eel: replace eel_ref_str with GRefString
GNOME/nautilus@b4d200f
https://developer.gnome.org/glib/stable/glib-Reference-counted-strings.html
Diffstat (limited to 'eel')
-rw-r--r-- | eel/eel-string.c | 112 | ||||
-rw-r--r-- | eel/eel-string.h | 10 |
2 files changed, 0 insertions, 122 deletions
diff --git a/eel/eel-string.c b/eel/eel-string.c index aea801ea..c44706c1 100644 --- a/eel/eel-string.c +++ b/eel/eel-string.c @@ -746,118 +746,6 @@ eel_strdup_printf_with_custom (EelPrintfHandler *handlers, return res; } -/*********** refcounted strings ****************/ - -G_LOCK_DEFINE_STATIC (unique_ref_strs); -static GHashTable *unique_ref_strs = NULL; - -static eel_ref_str -eel_ref_str_new_internal (const char *string, int start_count) -{ - char *res; - volatile gint *count; - gsize len; - - len = strlen (string); - res = g_malloc (sizeof (gint) + len + 1); - count = (volatile gint *)res; - *count = start_count; - res += sizeof(gint); - memcpy (res, string, len + 1); - return res; -} - -eel_ref_str -eel_ref_str_new (const char *string) -{ - if (string == NULL) - { - return NULL; - } - - return eel_ref_str_new_internal (string, 1); -} - -eel_ref_str -eel_ref_str_get_unique (const char *string) -{ - eel_ref_str res; - - if (string == NULL) - { - return NULL; - } - - G_LOCK (unique_ref_strs); - if (unique_ref_strs == NULL) - { - unique_ref_strs = - g_hash_table_new(g_str_hash, g_str_equal); - } - - res = g_hash_table_lookup (unique_ref_strs, string); - if (res != NULL) - { - eel_ref_str_ref (res); - } - else - { - res = eel_ref_str_new_internal (string, 0x80000001); - g_hash_table_insert (unique_ref_strs, res, res); - } - - G_UNLOCK (unique_ref_strs); - - return res; -} - -eel_ref_str -eel_ref_str_ref (eel_ref_str str) -{ - volatile gint *count; - - count = (volatile gint *)((char *)str - sizeof (gint)); - g_atomic_int_add (count, 1); - - return str; -} - -void -eel_ref_str_unref (eel_ref_str str) -{ - volatile gint *count; - gint old_ref; - - if (str == NULL) - return; - - count = (volatile gint *)((char *)str - sizeof (gint)); - -retry_atomic_decrement: - old_ref = g_atomic_int_get (count); - if (old_ref == 1) - { - g_free ((char *)count); - } - else if (old_ref == 0x80000001) - { - G_LOCK (unique_ref_strs); - /* Need to recheck after taking lock to avoid races with _get_unique() */ - if (g_atomic_int_add (count, -1) == 0x80000001) - { - g_hash_table_remove (unique_ref_strs, (char *)str); - g_free ((char *)count); - } - G_UNLOCK (unique_ref_strs); - } - else if (!g_atomic_int_compare_and_exchange (count, - old_ref, old_ref - 1)) - { - goto retry_atomic_decrement; - } -} - - #if !defined (EEL_OMIT_SELF_CHECK) static void diff --git a/eel/eel-string.h b/eel/eel-string.h index 929d11a2..27c829e8 100644 --- a/eel/eel-string.h +++ b/eel/eel-string.h @@ -79,16 +79,6 @@ char * eel_str_replace_substring (const char *str, const char *substring, const char *replacement); -typedef char * eel_ref_str; - -eel_ref_str eel_ref_str_new (const char *string); -eel_ref_str eel_ref_str_get_unique (const char *string); -eel_ref_str eel_ref_str_ref (eel_ref_str str); -void eel_ref_str_unref (eel_ref_str str); - -#define eel_ref_str_peek(__str) ((const char *)(__str)) - - typedef struct { char character; |