summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2013-07-28 11:36:42 +0200
committerDaniel Carl <danielcarl@gmx.de>2013-07-28 11:36:42 +0200
commit35a4f777f708bcbfe87544b2c57ef967bde4a018 (patch)
tree25403742dcf14ae03612806ae1d3eeddabed4cf3 /src/util.c
parent8595b3d47c454cc0acd7f255f0cd77bc2eefcf8a (diff)
Little history precessing improvement.
The history files and items list must be made unique so we generated a list and removed old items that where equal to a new to insert item. This caused some deletions in the GList that are not necessary. Now the file lines are processed from the last to the first. That means, every new item (older item in file) that is already is in the list can be discarded, because the latest is already in the GList.
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/util.c b/src/util.c
index da3b646..bed23d4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -111,7 +111,10 @@ GList *util_file_to_unique_list(const char *filename, Util_Content_Func func,
return gl;
}
- for (int i = 0; i < len; i++) {
+ /* begin with tha last line of the file to make unique check easier -
+ * every already existing item in the list is the latest, so we don't need
+ * to romove items from the list which takes some time */
+ for (int i = len - 1; i >= 0; i--) {
line = lines[i];
g_strstrip(line);
if (*line == '\0') {
@@ -119,19 +122,16 @@ GList *util_file_to_unique_list(const char *filename, Util_Content_Func func,
}
if ((value = func(line))) {
- /* if the value is already in list, remove this entry */
- for (GList *l = gl; l; l = l->next) {
- if (!unique_func(value, l->data)) {
- free_func(l->data);
- gl = g_list_delete_link(gl, l);
- break;
- }
+ /* if the value is already in list, free it and don't put it onto
+ * the list */
+ if (g_list_find_custom(gl, value, unique_func)) {
+ free_func(value);
+ } else {
+ gl = g_list_prepend(gl, value);
}
- gl = g_list_prepend(gl, value);
}
}
g_strfreev(lines);
- gl = g_list_reverse(gl);
return gl;
}