From e552489427e4d950c182a3a0221896ae65529a85 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Mon, 17 Nov 2008 04:38:00 +0000 Subject: Convert for-if-break construct to do while git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@75 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- linear.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/linear.c b/linear.c index c54c7f4..4495f51 100644 --- a/linear.c +++ b/linear.c @@ -74,7 +74,6 @@ DoLU(void) double* bbase = NULL; LUdblptr ptra; int n; - int i; static int num_arrays = 0; static bool is_adjusted = false; @@ -109,9 +108,10 @@ DoLU(void) if (is_adjusted == false) { is_adjusted = true; - for(i=1;i<=ARRAY_MAX;i++) - { - abase = realloc(abase, sizeof(double) * LUARRAYCOLS*LUARRAYROWS*(i+1)); + do { + ++num_arrays; + + abase = realloc(abase, sizeof(double) * LUARRAYCOLS * LUARRAYROWS * (num_arrays + 1)); if (!abase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(a); @@ -120,7 +120,7 @@ DoLU(void) exit(1); } - bbase = realloc(bbase, sizeof(double) * LUARRAYROWS*(i+1)); + bbase = realloc(bbase, sizeof(double) * LUARRAYROWS * (num_arrays + 1)); if (!bbase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(a); @@ -129,11 +129,8 @@ DoLU(void) free(LUtempvv); exit(1); } - if(DoLUIteration(a,b,abase,bbase,i)>MINIMUM_TICKS) - { num_arrays=i; - break; - } - } + } while ((DoLUIteration(a, b, abase, bbase, num_arrays) <= MINIMUM_TICKS) && (num_arrays <= ARRAY_MAX)); + /* ** Were we able to do it? */ @@ -151,7 +148,7 @@ DoLU(void) ** Don't need to adjust -- just allocate the proper ** number of arrays and proceed. */ - abase = malloc(sizeof(double) * LUARRAYCOLS*LUARRAYROWS*num_arrays); + abase = malloc(sizeof(double) * LUARRAYCOLS * LUARRAYROWS * num_arrays); if (!abase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(a); @@ -160,7 +157,7 @@ DoLU(void) exit(1); } - bbase = malloc(sizeof(double) * LUARRAYROWS*num_arrays); + bbase = malloc(sizeof(double) * LUARRAYROWS * num_arrays); if (!bbase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(a); -- cgit v1.2.3