clpr/cfloat.m: free list handling

Fergus Henderson fjh at mundook.cs.mu.OZ.AU
Wed Sep 3 16:30:16 AEST 1997


Oh, I see it is possible to improve efficiency a bit
by avoiding the `prev' pointer.

clpr/cfloat.m:
	Improve efficiency slightly by eliminating the `prev'
	pointer in the ML_cfloat_choicepoint_entry structure.

cvs diff: Diffing .
Index: cfloat.m
===================================================================
RCS file: /home/staff/zs/imp/clpr/cfloat.m,v
retrieving revision 1.3
diff -u -u -r1.3 cfloat.m
--- 1.3	1997/09/02 19:29:57
+++ cfloat.m	1997/09/03 05:51:54
@@ -318,7 +318,8 @@
 **	- the CLP(R) trail
 ** The Mercury trail contains function trail entries which point to
 ** the cfloat.m choice point stack.
-** The cfloat.m choice point stack is represented a doubly-linked list.
+** The cfloat.m choice point stack is represented a singly-linked list,
+** with a free list used to minimize the cost of memory allocation.
 ** Its entries store the values of the CLP(R) global variables, including
 ** the `trtop' variable, which points to the top of the CLP(R) trail.
 */
@@ -327,25 +328,12 @@
 	int slack_id;
 	int solver_id;
 	int trtop;
-	struct ML_cfloat_choicepoint *prev;
 	struct ML_cfloat_choicepoint *next;
 } ML_cfloat_choicepoint;
 
 ML_cfloat_choicepoint ML_cfloat_first_choicepoint;
 ML_cfloat_choicepoint * ML_cfloat_current_cp = &ML_cfloat_first_choicepoint;
 
-#define ML_cfloat_next_choicepoint()					\
-	( ML_cfloat_current_cp->next == NULL ?				\
-		(ML_cfloat_current_cp->next = make(ML_cfloat_choicepoint), \
-		ML_cfloat_current_cp->next->next = NULL,		\
-		ML_cfloat_current_cp->next->prev = ML_cfloat_current_cp,\
-		ML_cfloat_current_cp = ML_cfloat_current_cp->next)	\
-	:								\
-		(ML_cfloat_current_cp = ML_cfloat_current_cp->next)	\
-	)
-#define ML_cfloat_prev_choicepoint() \
-	(ML_cfloat_current_cp = ML_cfloat_current_cp->prev)
-		
 #define ML_cfloat_maybe_trail_solver()				\
 	do {							\
 		if (stamp != MR_current_choicepoint_id()) {	\
@@ -365,12 +353,21 @@
 void
 ML_cfloat_trail_solver(void)
 {
-	ML_cfloat_choicepoint *choicepoint = ML_cfloat_next_choicepoint();
+	ML_cfloat_choicepoint *choicepoint = ML_cfloat_current_cp;
 	choicepoint->stamp = stamp;
 	choicepoint->slack_id = slack_id;
 	choicepoint->solver_id = solver_id;
 	choicepoint->trtop = trtop;
 	MR_trail_function(ML_cfloat_untrail_func, (Word) choicepoint);
+
+	if (choicepoint->next == NULL) {
+		ML_cfloat_choicepoint *next_choicepoint;
+		next_choicepoint = make(ML_cfloat_choicepoint);
+		next_choicepoint->next = NULL;
+		choicepoint->next = next_choicepoint;
+	}
+	ML_cfloat_current_cp = choicepoint->next;
+
 	stamp = MR_current_choicepoint_id();
 }
 
@@ -405,7 +402,7 @@
 		default:
 			fatal_error(""cfloat.m: unknown MR_untrail_reason"");
 	}
-	ML_cfloat_prev_choicepoint();
+	ML_cfloat_current_cp = choicepoint;
 }
 ").
 
--
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list