commit 6abb27e6d584d9a50c45275f385d61cafd15aeb7
parent c313ec9aa7098fbc7645c432086ac81a64a5dee4
Author: Colin Leroy <colin@colino.net>
Date: Wed, 10 Oct 2012 07:19:18 +0000
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@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.
Diffstat:
4 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,13 @@
+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@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.
+
2012-10-09 [mones] 3.8.1cvs86
* doc/man/claws-mail.1
diff --git a/PATCHSETS b/PATCHSETS
@@ -4461,3 +4461,4 @@
( cvs diff -u -r 1.179.2.266 -r 1.179.2.267 src/imap.c; ) > 3.8.1cvs84.patchset
( cvs diff -u -r 1.53.2.38 -r 1.53.2.39 po/POTFILES.in; cvs diff -u -r 1.274.2.353 -r 1.274.2.354 src/mainwindow.c; cvs diff -u -r 1.9.2.59 -r 1.9.2.60 src/common/defs.h; cvs diff -u -r 1.5.2.47 -r 1.5.2.48 src/gtk/menu.c; cvs diff -u -r 1.4.2.27 -r 1.4.2.28 src/gtk/menu.h; ) > 3.8.1cvs85.patchset
( cvs diff -u -r 1.396.2.3641 -r 1.396.2.3642 ChangeLog; cvs diff -u -r 1.1.2.10 -r 1.1.2.11 doc/man/claws-mail.1; cvs diff -u -r 1.382.2.613 -r 1.382.2.614 src/compose.c; cvs diff -u -r 1.36.2.201 -r 1.36.2.202 src/common/utils.c; ) > 3.8.1cvs86.patchset
+( cvs diff -u -r 1.36.2.202 -r 1.36.2.203 src/common/utils.c; ) > 3.8.1cvs87.patchset
diff --git a/configure.ac b/configure.ac
@@ -12,7 +12,7 @@ MINOR_VERSION=8
MICRO_VERSION=1
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=86
+EXTRA_VERSION=87
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=
diff --git a/src/common/utils.c b/src/common/utils.c
@@ -258,14 +258,10 @@ void list_free_strings(GList *list)
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 @@ gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist)
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 @@ gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist)
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");