# HG changeset patch # User zas_ # Date 1213097255 0 # Node ID 7daea970a89a07bb4d31ce82d08299d8890df854 # Parent 721c2bbaceece10b22934e4fb504e3a70d9658c6 collection_info_list_to_dnd_data(): simplify and optimize. diff -r 721c2bbaceec -r 7daea970a89a src/collect.c --- a/src/collect.c Mon Jun 09 20:27:39 2008 +0000 +++ b/src/collect.c Tue Jun 10 11:27:35 2008 +0000 @@ -472,63 +472,59 @@ gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *length) { - gchar *uri_text = NULL; - gint total; GList *work; - gint n; - GList *temp; + GList *temp = NULL; gchar *ptr; - - n = collection_to_number(cd); + gchar *text; + gchar *uri_text; + gint collection_number; - if (!list || n < 0) - { - *length = 0; - return NULL; - } + *length = 0; + if (!list) return NULL; - temp = NULL; - temp = g_list_prepend(temp, g_strdup_printf("COLLECTION:%d\n", n)); + collection_number = collection_to_number(cd); + if (collection_number < 0) return NULL; + + text = g_strdup_printf("COLLECTION:%d\n", collection_number); + *length += strlen(text); + temp = g_list_prepend(temp, text); + work = list; while (work) { - n = g_list_index(cd->list, work->data); - if (n >= 0) - { - temp = g_list_prepend(temp, g_strdup_printf("%d\n", n)); - } + gint item_number = g_list_index(cd->list, work->data); + work = work->next; + + if (item_number < 0) continue; + + text = g_strdup_printf("%d\n", item_number); + temp = g_list_prepend(temp, text); + *length += strlen(text); } - total = 0; - work = temp; - while (work) - { - total += strlen((gchar *)work->data); - work = work->next; - } - total += 1; + *length += 1; /* ending nul char */ - uri_text = g_malloc(total); + uri_text = g_malloc(*length); ptr = uri_text; work = g_list_last(temp); while (work) { + gint len; gchar *text = work->data; work = work->prev; - strcpy(ptr, text); - ptr += strlen(text); + len = strlen(text); + memcpy(ptr, text, len); + ptr += len; } ptr[0] = '\0'; string_list_free(temp); - *length = total; - return uri_text; }