# HG changeset patch # User zas_ # Date 1213098918 0 # Node ID cf5bbd0beaae4b36d0af6aaec7fe0a4413ea7664 # Parent 7daea970a89a07bb4d31ce82d08299d8890df854 collection_from_dnd_data(): simplify and optimize. diff -r 7daea970a89a -r cf5bbd0beaae src/collect.c --- a/src/collect.c Tue Jun 10 11:27:35 2008 +0000 +++ b/src/collect.c Tue Jun 10 11:55:18 2008 +0000 @@ -427,46 +427,45 @@ CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList **info_list) { CollectionData *cd; - gint n; + gint collection_number; + const gchar *ptr; + + if (list) *list = NULL; + if (info_list) *info_list = NULL; if (strncmp(data, "COLLECTION:", 11) != 0) return NULL; - - n = (gint)strtol(data + 11, NULL, 10); - cd = collection_from_number(n); + + ptr = data + 11; + + collection_number = atoi(ptr); + cd = collection_from_number(collection_number); + if (!cd) return NULL; - if (!cd || (!list && !info_list)) - { - return cd; - } - else - { - GList *work = NULL; - GList *infol = NULL; - gint b, e; - - b = 0; - while (data[b] != '\0' && data[b] != '\n' ) b++; - b++; - e = b; + if (!list && !info_list) return cd; + + while (*ptr != '\0' && *ptr != '\n' ) ptr++; + if (*ptr == '\0') return cd; + ptr++; - while (data[b] != '\0') - { - CollectInfo *info; - - while (data[e] != '\n' && data[e] != '\0') e++; - n = (gint)strtol(data + b, NULL, 10); + while (*ptr != '\0') + { + guint item_number; + CollectInfo *info; + + item_number = (guint) atoi(ptr); + while (*ptr != '\n' && *ptr != '\0') ptr++; + if (*ptr == '\0') + break; + else + while (*ptr == '\n') ptr++; - info = g_list_nth_data(cd->list, n); - if (info && list) work = g_list_append(work, file_data_ref(info->fd)); - if (info && info_list) infol = g_list_append(infol, info); + info = g_list_nth_data(cd->list, item_number); + if (!info) continue; - while (data[e] == '\n') e++; - b = e; - } - if (list) *list = work; - if (info_list) *info_list = infol; + if (list) *list = g_list_append(*list, file_data_ref(info->fd)); + if (info_list) *info_list = g_list_append(*info_list, info); } - + return cd; }