2003-08-27  Jody Goldberg <jody@gnome.org>

	* src/dependent.c (dependent_link) : keep a tail pointer and append
	  new dependents to the list.  This is a slightly better fit to the
	  common idiom of starting at the top and working down, and papers
	  over the most common case of ultra deep recursion blowing the stack.
	  We'll need to solve this more rigorously during 1.3.
	(dependent_unlink) : ditto.
	(gnm_dep_container_new) : ditto.

 Morten:
 	* Support End+Home key sequence.
Index: src/dependent.c
===================================================================
RCS file: /cvs/gnome/gnumeric/src/dependent.c,v
retrieving revision 1.217
diff -u -w -r1.217 dependent.c
--- src/dependent.c	27 Aug 2003 00:33:03 -0000	1.217
+++ src/dependent.c	27 Aug 2003 15:18:38 -0000
@@ -1051,12 +1051,14 @@
 
 	sheet = dep->sheet;
 
-	/* Make this the new head of the dependent list.  */
-	dep->prev_dep = NULL;
-	dep->next_dep = sheet->deps->dependent_list;
-	if (dep->next_dep)
-		dep->next_dep->prev_dep = dep;
-	sheet->deps->dependent_list = dep;
+	/* Make this the new tail of the dependent list.  */
+	dep->prev_dep = sheet->deps->tail;
+	dep->next_dep = NULL;
+	if (dep->prev_dep)
+		dep->prev_dep->next_dep = dep;
+	else
+		sheet->deps->head = dep; /* first element */
+	sheet->deps->tail = dep;
 	dep->flags |=
 		DEPENDENT_IS_LINKED |
 		link_expr_dep (dep, pos, dep->expression);
@@ -1076,6 +1078,8 @@
 void
 dependent_unlink (Dependent *dep, CellPos const *pos)
 {
+	GnmDepContainer *contain;
+
 	g_return_if_fail (dep != NULL);
 	g_return_if_fail (dependent_is_linked (dep));
 	g_return_if_fail (dep->expression != NULL);
@@ -1085,9 +1089,12 @@
 		pos = (dependent_is_cell (dep)) ? &DEP_TO_CELL(dep)->pos : &dummy;
 
 	unlink_expr_dep (dep, pos, dep->expression);
-	if (dep->sheet->deps != NULL) {
-		if (dep->sheet->deps->dependent_list == dep)
-			dep->sheet->deps->dependent_list = dep->next_dep;
+	contain = dep->sheet->deps;
+	if (contain != NULL) {
+		if (contain->head == dep)
+			contain->head = dep->next_dep;
+		if (contain->tail == dep)
+			contain->tail = dep->prev_dep;
 		if (dep->next_dep)
 			dep->next_dep->prev_dep = dep->prev_dep;
 		if (dep->prev_dep)
@@ -2090,7 +2097,7 @@
 {
 	GnmDepContainer *deps = g_new (GnmDepContainer, 1);
 
-	deps->dependent_list = NULL;
+	deps->head = deps->tail = NULL;
 
 	deps->range_hash  = g_new0 (GHashTable *,
 				    (SHEET_MAX_ROWS-1)/BUCKET_SIZE + 1);
Index: src/dependent.h
===================================================================
RCS file: /cvs/gnome/gnumeric/src/dependent.h,v
retrieving revision 1.61
diff -u -w -r1.61 dependent.h
--- src/dependent.h	27 Mar 2003 19:35:24 -0000	1.61
+++ src/dependent.h	27 Aug 2003 15:18:38 -0000
@@ -55,7 +55,7 @@
 #define dependent_is_linked(dep)	((dep)->flags & DEPENDENT_IS_LINKED)
 
 struct _GnmDepContainer {
-	Dependent *dependent_list;
+	Dependent *head, *tail;
 
 	/* Large ranges hashed on 'range' to accelerate duplicate culling. This
 	 * is tranversed by g_hash_table_foreach mostly.
@@ -117,7 +117,7 @@
 
 #define DEPENDENT_CONTAINER_FOREACH_DEPENDENT(dc, dep, code)	\
   do {								\
-	Dependent *dep = (dc)->dependent_list;			\
+	Dependent *dep = (dc)->head;				\
 	while (dep) {						\
 		Dependent *_next = dep->next_dep;		\
 		code;						\
