summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorJordan Petridis <jpetridis@gnome.org>2018-12-10 19:55:38 +0200
committerCarlos Soriano <csoriano1618+gnome@gmail.com>2019-02-22 11:29:57 +0000
commitb4d200fed3610f52620c69f1cd271a0e5aa34462 (patch)
treec507ecd73fbbaa22db180054efc8187bf1343194 /eel
parentde17081ff2d966fcde3d0069bb82c6f2441270a9 (diff)
downloadnautilus-b4d200fed3610f52620c69f1cd271a0e5aa34462.tar.gz
file: replace eel_ref_str with GRefString
glib now offers a reference counted api. This allows us to replace a lot of legacy code and get rid of eel_ref_str. GRefString [1] is almost a drop-in replacement. nautilus-file-operations.c was indirectly depending upon eel/eel-string.h from nautilus-file-private.h and thus a new include was added. This bumps the minimum version of glib to 2.58 Close #781 https://gitlab.gnome.org/GNOME/nautilus/issues/781 [1] https://developer.gnome.org/glib/stable/glib-Reference-counted-strings.html
Diffstat (limited to 'eel')
-rw-r--r--eel/eel-string.c115
-rw-r--r--eel/eel-string.h9
2 files changed, 0 insertions, 124 deletions
diff --git a/eel/eel-string.c b/eel/eel-string.c
index 077c1c379..6720d0af6 100644
--- a/eel/eel-string.c
+++ b/eel/eel-string.c
@@ -365,121 +365,6 @@ enum
ARG_TYPE_POINTER
};
-/*********** 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)
void
diff --git a/eel/eel-string.h b/eel/eel-string.h
index 63147d1cc..a83375055 100644
--- a/eel/eel-string.h
+++ b/eel/eel-string.h
@@ -77,12 +77,3 @@ char * eel_str_replace_substring (const char *str,
* common prefix of length min_required_len
*/
char * eel_str_get_common_prefix (GList *strs, int min_required_len);
-
-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)) \ No newline at end of file