From: Ricardo Mones Date: Tue, 11 Feb 2014 00:14:45 +0000 (+0100) Subject: New slist_copy_deep utility X-Git-Tag: 3.10.0~204 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=b1983f360ba1028fd0b9dec05e3ac1b7982cdb04 New slist_copy_deep utility And refactoring to use it where currently needed. Implementation uses glib's version if possible (glib > 2.34). --- diff --git a/src/addrduplicates.c b/src/addrduplicates.c index 2812a977d..cc3bb22c0 100644 --- a/src/addrduplicates.c +++ b/src/addrduplicates.c @@ -66,7 +66,7 @@ static void cb_finder_results_dialog_destroy(GtkWindow*, gpointer); static gboolean cb_finder_results_dialog_key_pressed(GtkWidget*, GdkEventKey*, gpointer); static void destroy_addr_hash_val(gpointer); -static GSList* deep_copy_hash_val(GSList*); +static AddrDupListEntry *copy_hash_val(AddrDupListEntry *); static void fill_hash_table(); static gint collect_emails(ItemPerson*, AddressDataSource*); static gboolean is_not_duplicate(gpointer, gpointer, gpointer); @@ -187,24 +187,14 @@ static void destroy_addr_hash_val(gpointer value) g_slist_free(list); } -static GSList* deep_copy_hash_val(GSList *in) +static AddrDupListEntry *copy_hash_val(AddrDupListEntry *entry) { - GSList *walk; - GSList *out = NULL; - - out = g_slist_copy(in); - for(walk = out; walk; walk = walk->next) { - AddrDupListEntry *out_entry; - AddrDupListEntry *in_entry = walk->data; - - out_entry = g_new0(AddrDupListEntry,1); - out_entry->person = in_entry->person; - out_entry->ds = in_entry->ds; - out_entry->book_path = g_strdup(in_entry->book_path); - walk->data = out_entry; - } + AddrDupListEntry *new = g_new0(AddrDupListEntry, 1); + new->person = entry->person; + new->ds = entry->ds; + new->book_path = g_strdup(entry->book_path); - return out; + return new; } static void fill_hash_table() @@ -282,7 +272,7 @@ static gint collect_emails(ItemPerson *itemperson, AddressDataSource *ds) addr = g_utf8_strdown(email->address, -1); old_val = g_hash_table_lookup(addr_hash, addr); if(old_val) - new_val = deep_copy_hash_val(old_val); + new_val = slist_copy_deep(old_val, copy_hash_val); else new_val = NULL; diff --git a/src/common/utils.c b/src/common/utils.c index ff476f155..ef8c6b60a 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -237,6 +237,21 @@ gint mkstemp(gchar *template) } #endif /* G_OS_WIN32 */ +GSList *slist_copy_deep(GSList *list, GCopyFunc func) +{ +#if GLIB_CHECK_VERSION(2, 34, 0) + return g_slist_copy_deep(list, func, NULL); +#else + GSList *res = g_slist_copy(list); + GSList *walk = res; + while (walk) { + walk->data = func(walk->data, NULL); + walk = walk->next; + } + return res; +#endif +} + void list_free_strings(GList *list) { list = g_list_first(list); diff --git a/src/common/utils.h b/src/common/utils.h index 8766ff28e..a0c46191a 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -273,6 +273,10 @@ gboolean debug_get_mode (void); gboolean superuser_p (void); +/* List utilities. */ + +GSList *slist_copy_deep (GSList *list, + GCopyFunc func); /* String utilities. */