[Commits] utils.c 1.36.2.202 1.36.2.203
colin at claws-mail.org
colin at claws-mail.org
Wed Oct 10 09:19:20 CEST 2012
Update of /home/claws-mail/claws/src/common
In directory srv:/tmp/cvs-serv20004/src/common
Modified Files:
Tag: gtk2
utils.c
Log Message:
2012-10-10 [colin] 3.8.1cvs87
* src/common/utils.c
Fix O(n^2) algorithm in remove_numbered_files_not_in_list
Initial patch by Igor Mammedov <imammedo at redhat.com> with
fixes by Michael Rasmussen and myself.
Also revert part of 3.8.1cvs86, g_slist_free_full()
semantics are different from slist_free_strings() in that
slist_free_strings does not free the list itself.
Index: utils.c
===================================================================
RCS file: /home/claws-mail/claws/src/common/utils.c,v
retrieving revision 1.36.2.202
retrieving revision 1.36.2.203
diff -u -d -r1.36.2.202 -r1.36.2.203
--- utils.c 9 Oct 2012 23:58:43 -0000 1.36.2.202
+++ utils.c 10 Oct 2012 07:19:18 -0000 1.36.2.203
@@ -258,14 +258,10 @@
void slist_free_strings(GSList *list)
{
-#if GLIB_CHECK_VERSION(2,28,0)
- g_slist_free_full(list, (GDestroyNotify)g_free);
-#else
while (list != NULL) {
g_free(list->data);
list = list->next;
}
-#endif
}
static void hash_free_strings_func(gpointer key, gpointer value, gpointer data)
@@ -2382,6 +2378,10 @@
const gchar *dir_name;
gchar *prev_dir;
gint file_no;
+ GHashTable *file_no_tbl;
+
+ if (numberlist == NULL)
+ return 0;
prev_dir = g_get_current_dir();
@@ -2397,18 +2397,26 @@
return -1;
}
+ file_no_tbl = g_hash_table_new(g_direct_hash, g_direct_equal);
while ((dir_name = g_dir_read_name(dp)) != NULL) {
file_no = to_number(dir_name);
- if (file_no > 0 && (g_slist_find(numberlist, GINT_TO_POINTER(file_no)) == NULL)) {
- debug_print("removing unwanted file %d from %s\n", file_no, dir);
- if (is_dir_exist(dir_name))
- continue;
+ if (is_dir_exist(dir_name))
+ continue;
+ if (file_no > 0)
+ g_hash_table_insert(file_no_tbl, GINT_TO_POINTER(file_no), GINT_TO_POINTER(1));
+ }
+
+ do {
+ if (g_hash_table_lookup(file_no_tbl, numberlist->data) == NULL) {
+ debug_print("removing unwanted file %d from %s\n",
+ GPOINTER_TO_INT(numberlist->data), dir);
if (claws_unlink(dir_name) < 0)
FILE_OP_ERROR(dir_name, "unlink");
}
- }
+ } while ((numberlist = g_slist_next(numberlist)));
g_dir_close(dp);
+ g_hash_table_destroy(file_no_tbl);
if (g_chdir(prev_dir) < 0) {
FILE_OP_ERROR(prev_dir, "chdir");
More information about the Commits
mailing list