From: John Darrington Date: Tue, 15 Nov 2011 14:14:30 +0000 (+0100) Subject: sweep.c: Reduce scope of local variables and avoid reusing them. X-Git-Tag: v0.7.9~88 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8f1c67b087b875d45c28bcae330910e7723d6c6;p=pspp-builds.git sweep.c: Reduce scope of local variables and avoid reusing them. This makes the code easier to follow, and helps the compiler with optimisation. --- diff --git a/lib/linreg/sweep.c b/lib/linreg/sweep.c index 0f8c223c..c2184564 100644 --- a/lib/linreg/sweep.c +++ b/lib/linreg/sweep.c @@ -75,8 +75,6 @@ reg_sweep (gsl_matrix * A, int last_col) if (A->size1 != A->size2) return GSL_ENOTSQR; - double sweep_element; - double tmp; int i; int j; int k; @@ -90,11 +88,10 @@ reg_sweep (gsl_matrix * A, int last_col) B = gsl_matrix_alloc (A->size1, A->size2); for (k = 0; k < (A->size1 - 1); k++) { - sweep_element = gsl_matrix_get (A, k, k); + const double sweep_element = gsl_matrix_get (A, k, k); if (fabs (sweep_element) > GSL_DBL_MIN) { - tmp = -1.0 / sweep_element; - gsl_matrix_set (B, k, k, tmp); + gsl_matrix_set (B, k, k, -1.0 / sweep_element); /* Rows before current row k. */ @@ -102,9 +99,8 @@ reg_sweep (gsl_matrix * A, int last_col) { for (j = i; j < A->size2; j++) { - /* - Use only the upper triangle of A. - */ + /* Use only the upper triangle of A. */ + double tmp; if (j < k) { tmp = gsl_matrix_get (A, i, j) - @@ -131,7 +127,7 @@ reg_sweep (gsl_matrix * A, int last_col) */ for (j = k + 1; j < A->size1; j++) { - tmp = gsl_matrix_get (A, k, j) / sweep_element; + double tmp = gsl_matrix_get (A, k, j) / sweep_element; gsl_matrix_set (B, k, j, tmp); } /* @@ -141,7 +137,7 @@ reg_sweep (gsl_matrix * A, int last_col) { for (j = i; j < A->size2; j++) { - tmp = gsl_matrix_get (A, i, j) - + double tmp = gsl_matrix_get (A, i, j) - gsl_matrix_get (A, k, i) * gsl_matrix_get (A, k, j) / sweep_element; gsl_matrix_set (B, i, j, tmp);