# HG changeset patch # User zas_ # Date 1216556412 0 # Node ID 518c05cf63ba527ac9f0b32b8324ba414cb75e38 # Parent 6c676d3eef5bc45935039b6e7f864f50e16fd996 Optimize history_list_add_to_key() a bit. diff -r 6c676d3eef5b -r 518c05cf63ba src/ui_bookmark.c --- a/src/ui_bookmark.c Sun Jul 20 11:29:12 2008 +0000 +++ b/src/ui_bookmark.c Sun Jul 20 12:20:12 2008 +0000 @@ -254,13 +254,18 @@ while (work) { gchar *buf = work->data; - work = work->next; + if (strcmp(buf, path) == 0) { - hd->list = g_list_remove(hd->list, buf); - hd->list = g_list_prepend(hd->list, buf); + /* if not first, move it */ + if (work != hd->list) + { + hd->list = g_list_remove(hd->list, buf); + hd->list = g_list_prepend(hd->list, buf); + } return; } + work = work->next; } hd->list = g_list_prepend(hd->list, g_strdup(path)); @@ -268,12 +273,26 @@ if (max == -1) max = HISTORY_DEFAULT_KEY_COUNT; if (max > 0) { - while (hd->list && g_list_length(hd->list) > (guint) max) + gint len = 0; + GList *work = hd->list; + GList *last = NULL; + + while (work) { - GList *work = g_list_last(hd->list); - gchar *buf = work->data; - hd->list = g_list_remove(hd->list, buf); - g_free(buf); + len++; + last = work; + work = work->next; + } + + work = last; + while (work && len > max) + { + GList *node = work; + work = work->prev; + + g_free(node->data); + hd->list = g_list_delete_link(hd->list, node); + len--; } } }