[gnumeric] collect: simplify handling of missing values.



commit bea66e5fa192f677d910b3ab26b26359439c6fe6
Author: Morten Welinder <terra gnome org>
Date:   Fri Jun 11 11:00:14 2010 -0400

    collect: simplify handling of missing values.

 plugins/fn-tsa/functions.c |   68 +++++--------------------------------------
 src/collect.c              |   33 ++++++---------------
 src/collect.h              |    2 +-
 3 files changed, 18 insertions(+), 85 deletions(-)
---
diff --git a/plugins/fn-tsa/functions.c b/plugins/fn-tsa/functions.c
index 194f280..1ddfb01 100644
--- a/plugins/fn-tsa/functions.c
+++ b/plugins/fn-tsa/functions.c
@@ -561,26 +561,9 @@ gnumeric_interpolation (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 			value_release (values[i]);
 	} else {
 		if (missing0 || missing1) {
-			GSList *missing ;
-			GArray *gval;
-
-			missing = gnm_slist_sort_merge (missing0, missing1);
-			gval = g_array_new (FALSE, FALSE, sizeof (gnm_float));
-			gval = g_array_append_vals (gval, vals0, n0);
-			g_free (vals0);
-			gnm_strip_missing (gval, missing);
-			vals0 = (gnm_float *) gval->data;
-			n0 = gval->len;
-			g_array_free (gval, FALSE);
-
-			gval = g_array_new (FALSE, FALSE, sizeof (gnm_float));
-			gval = g_array_append_vals (gval, vals1, n1);
-			g_free (vals1);
-			gnm_strip_missing (gval, missing);
-			vals1 = (gnm_float *) gval->data;
-			n1 = gval->len;
-			g_array_free (gval, FALSE);
-
+			GSList *missing = gnm_slist_sort_merge (missing0, missing1);
+			gnm_strip_missing (vals0, &n0, missing);
+			gnm_strip_missing (vals1, &n1, missing);
 			g_slist_free (missing);
 
 			if (n0 != n1) {
@@ -745,26 +728,9 @@ gnumeric_periodogram (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 			interp = INTERPOLATION_LINEAR;
 
 		if (missing0 || missing1) {
-			GSList *missing ;
-			GArray *gval;
-
-			missing = gnm_slist_sort_merge (missing0, missing1);
-			gval = g_array_new (FALSE, FALSE, sizeof (gnm_float));
-			gval = g_array_append_vals (gval, ord, n0);
-			g_free (ord);
-			gnm_strip_missing (gval, missing);
-			ord = (gnm_float *) gval->data;
-			n0 = gval->len;
-			g_array_free (gval, FALSE);
-
-			gval = g_array_new (FALSE, FALSE, sizeof (gnm_float));
-			gval = g_array_append_vals (gval, absc, n1);
-			g_free (absc);
-			gnm_strip_missing (gval, missing);
-			absc = (gnm_float *) gval->data;
-			n1 = gval->len;
-			g_array_free (gval, FALSE);
-
+			GSList *missing = gnm_slist_sort_merge (missing0, missing1);
+			gnm_strip_missing (ord, &n0, missing);
+			gnm_strip_missing (absc, &n1, missing);
 			g_slist_free (missing);
 
 			if (n0 != n1)
@@ -842,16 +808,7 @@ gnumeric_periodogram (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	} else {
 		/* we have no interpolation to apply, so just take the values */
 		if (missing0) {
-			GArray *gval;
-
-			gval = g_array_new (FALSE, FALSE, sizeof (gnm_float));
-			gval = g_array_append_vals (gval, ord, n0);
-			g_free (ord);
-			gnm_strip_missing (gval, missing0);
-			ord = (gnm_float *) gval->data;
-			n0 = gval->len;
-			g_array_free (gval, FALSE);
-
+			gnm_strip_missing (ord, &n0, missing0);
 			g_slist_free (missing0);
 		}
 		nb = 1;
@@ -962,16 +919,7 @@ gnumeric_fourier (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	}
 
 	if (missing0) {
-		GArray *gval;
-
-		gval = g_array_new (FALSE, FALSE, sizeof (gnm_float));
-		gval = g_array_append_vals (gval, ord, n0);
-		g_free (ord);
-		gnm_strip_missing (gval, missing0);
-		ord = (gnm_float *) gval->data;
-		n0 = gval->len;
-		g_array_free (gval, FALSE);
-
+		gnm_strip_missing (ord, &n0, missing0);
 		g_slist_free (missing0);
 	}
 
diff --git a/src/collect.c b/src/collect.c
index 4e4606a..e8cd3db 100644
--- a/src/collect.c
+++ b/src/collect.c
@@ -548,23 +548,22 @@ gnm_slist_sort_merge (GSList *l1,
  *
  */
 void
-gnm_strip_missing (GArray *data, GSList *missing)
+gnm_strip_missing (gnm_float *data, int *n, GSList *missing)
 {
-	unsigned src, dst;;
+	unsigned src, dst;
 
 	if (missing == NULL)
 		return;
 
-	for (src = dst = 0; src < data->len; src++) {
-		if (missing && src == GPOINTER_TO_UINT (missing->data))
+	for (src = dst = 0; (int)dst < *n; src++) {
+		if (missing && src == GPOINTER_TO_UINT (missing->data)) {
 			missing = missing->next;
-		else {
-			g_array_index (data, gnm_float, dst) =
-				g_array_index (data, gnm_float, src);
+			(*n)--;
+		} else {
+			data[dst] = data[src];
 			dst++;
 		}
 	}
-	g_array_set_size (data, dst);
 }
 
 GnmValue *
@@ -605,22 +604,8 @@ float_range_function2d (GnmValue const *val0, GnmValue const *val1,
 
 		if (missing0 || missing1) {
 			GSList *missing = gnm_slist_sort_merge (missing0, missing1);
-			GArray *gval;
-			gval = g_array_new (FALSE, FALSE, sizeof (gnm_float));
-			gval = g_array_append_vals (gval, vals0, n0);
-			g_free (vals0);
-			gnm_strip_missing (gval, missing);
-			vals0 = (gnm_float *)gval->data;
-			n0 = gval->len;
-			g_array_free (gval, FALSE);
-
-			gval = g_array_new (FALSE, FALSE, sizeof (gnm_float));
-			gval = g_array_append_vals (gval, vals1, n1);
-			g_free (vals1);
-			gnm_strip_missing (gval, missing);
-			vals1 = (gnm_float *)gval->data;
-			n1 = gval->len;
-			g_array_free (gval, FALSE);
+			gnm_strip_missing (vals0, &n0, missing);
+			gnm_strip_missing (vals1, &n1, missing);
 
 			g_slist_free (missing);
 
diff --git a/src/collect.h b/src/collect.h
index 376a32f..f9f3197 100644
--- a/src/collect.h
+++ b/src/collect.h
@@ -68,7 +68,7 @@ GnmValue *string_range_function (int argc, GnmExprConstPtr const *argv,
 
 GSList *gnm_slist_sort_merge (GSList * list_1, GSList * list_2);
 
-void gnm_strip_missing (GArray * data, GSList *missing);
+void gnm_strip_missing (gnm_float* data, int *p, GSList *missing);
 
 
 G_END_DECLS



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]