Less calls to libc. Profiling is much better now.
authorviric@llimona
Fri, 16 Feb 2007 22:57:36 +0100
changeset 26 95fccfcbd04c
parent 25 b37843173279
child 27 545f73869d65
Less calls to libc. Profiling is much better now.
Makefile
algorithm.c
general.h
map.c
os.c
sokosol.c
--- a/Makefile	Sun May 07 13:34:25 2006 +0200
+++ b/Makefile	Fri Feb 16 22:57:36 2007 +0100
@@ -1,7 +1,11 @@
 CC=gcc
 
-# DEBUG
+# DEBUG for gprof
 CFLAGS=-pedantic -Wall -g -pg #-DDEBUG
 LDFLAGS=-pg -Wall
+#
+# DEBUG
+CFLAGS=-pedantic -Wall -g #-DDEBUG
+LDFLAGS=-Wall
 
 include Makefile.deps
--- a/algorithm.c	Sun May 07 13:34:25 2006 +0200
+++ b/algorithm.c	Fri Feb 16 22:57:36 2007 +0100
@@ -496,13 +496,16 @@
 }
 
 
-int solve_map(const struct Map origin)
+int solve_map(const struct Map *origin)
 {
-	struct Map maps[MAX_STEPS+1];
+	struct Map *maps;
 	struct BoxMove new_movements[MAX_MOVES];
 	int num_new_movements;
+	int ret;
 
-	CopyMap(&maps[0], &origin);
+	maps = malloc(sizeof(*maps) * (MAX_STEPS+1));
+
+	CopyMap(&maps[0], origin);
 
 	num_new_movements = get_box_movements(&maps[0], new_movements);
 	assert(num_new_movements < MAX_MOVES);
@@ -510,8 +513,9 @@
 
 	init_os();
 
-	return search_depth(maps, 0, new_movements,
+	ret = search_depth(maps, 0, new_movements,
 		num_new_movements, 100. / num_new_movements,
 		0);
-
+	free(maps);
+	return ret;
 }
--- a/general.h	Sun May 07 13:34:25 2006 +0200
+++ b/general.h	Fri Feb 16 22:57:36 2007 +0100
@@ -84,4 +84,4 @@
 
 /* Functions related to map solution
  * algorithm.c */
-int solve_map(const struct Map origin);
+int solve_map(const struct Map *origin);
--- a/map.c	Sun May 07 13:34:25 2006 +0200
+++ b/map.c	Fri Feb 16 22:57:36 2007 +0100
@@ -14,8 +14,10 @@
 	int i;
 	char tmp[MAX_Y][MAX_X]; /* !!!argh */
 
-	memset(tmp, 0, sizeof(tmp));
-
+	for (i=0; i < n; i++)
+	{
+		tmp[b2[i].y][b2[i].x] = 0;
+	}
 	for (i=0; i < n; i++)
 	{
 		tmp[b1[i].y][b1[i].x] = 1;
--- a/os.c	Sun May 07 13:34:25 2006 +0200
+++ b/os.c	Fri Feb 16 22:57:36 2007 +0100
@@ -169,7 +169,7 @@
 void init_os()
 {
 #ifndef DEBUG
-	program_alarm();
+//	program_alarm();
 #endif
 }
 
--- a/sokosol.c	Sun May 07 13:34:25 2006 +0200
+++ b/sokosol.c	Fri Feb 16 22:57:36 2007 +0100
@@ -43,5 +43,5 @@
 
 	init_os();
 
-	return solve_map(Morigin);
+	return solve_map(&Morigin);
 }