changeset 816:cf5bbd0beaae

collection_from_dnd_data(): simplify and optimize.
author zas_
date Tue, 10 Jun 2008 11:55:18 +0000
parents 7daea970a89a
children ad7f56cea841
files src/collect.c
diffstat 1 files changed, 32 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }