[gnumeric] Sheet cell listing refactoring.



commit 872af55142f760e4d725ba5b439e82e1695244b0
Author: Morten Welinder <terra gnome org>
Date:   Sun Oct 7 08:44:37 2012 -0400

    Sheet cell listing refactoring.

 ChangeLog      |    7 +++++++
 src/gnm-pane.c |    2 +-
 src/search.c   |    2 +-
 src/sheet.c    |   55 ++++++++++++++++++++++++++++++++++---------------------
 src/sheet.h    |    4 +++-
 src/workbook.c |    2 +-
 6 files changed, 47 insertions(+), 25 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6cd1272..86d3151 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-10-06  Morten Welinder  <terra gnome org>
+
+	* src/sheet.c (sheet_cell_positions): Renamed from sheet_cells.
+	All callers changed.
+	(sheet_cells): New function.
+	(sheet_foreach_cell_in_range): Use new sheet_cells.
+
 2012-09-26  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/sstest.c (test_random_normality): fix text
diff --git a/src/gnm-pane.c b/src/gnm-pane.c
index 8b6c2c9..ee43ba8 100644
--- a/src/gnm-pane.c
+++ b/src/gnm-pane.c
@@ -641,7 +641,7 @@ static gint
 gnm_pane_focus_in (GtkWidget *widget, GdkEventFocus *event)
 {
 	GnmPane *pane = GNM_PANE (widget);
-	gtk_im_context_focus_in (GNM_PANE (widget)->im_context);
+	gtk_im_context_focus_in (pane->im_context);
 	return (*GTK_WIDGET_CLASS (parent_klass)->focus_in_event) (widget, event);
 }
 
diff --git a/src/search.c b/src/search.c
index 9fd964f..e1acf05 100644
--- a/src/search.c
+++ b/src/search.c
@@ -217,7 +217,7 @@ gnm_search_collect_cells (GnmSearchReplace *sr)
 		break;
 
 	case GNM_SRS_SHEET:
-		cells = sheet_cells (sr->sheet, TRUE);
+		cells = sheet_cell_positions (sr->sheet, TRUE);
 		break;
 
 	case GNM_SRS_RANGE:
diff --git a/src/sheet.c b/src/sheet.c
index 552b6de..b7b5080 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -3727,8 +3727,8 @@ sheet_colrow_get_info (Sheet const *sheet, int colrow, gboolean is_cols)
 static gint
 cell_ordering (gconstpointer a_, gconstpointer b_)
 {
-	GnmCell const *a = a_;
-	GnmCell const *b = b_;
+	GnmCell const *a = *(GnmCell **)a_;
+	GnmCell const *b = *(GnmCell **)b_;
 
 	if (a->pos.row != b->pos.row)
 		return a->pos.row - b->pos.row;
@@ -3736,6 +3736,23 @@ cell_ordering (gconstpointer a_, gconstpointer b_)
 	return a->pos.col - b->pos.col;
 }
 
+GPtrArray *
+sheet_cells (Sheet *sheet)
+{
+	GPtrArray *res = g_ptr_array_new ();
+	GHashTableIter hiter;	
+	gpointer value;
+
+	g_hash_table_iter_init (&hiter, sheet->cell_hash);
+	while (g_hash_table_iter_next (&hiter, NULL, &value)) {
+		g_ptr_array_add (res, value);
+	}
+	g_ptr_array_sort (res, cell_ordering);
+
+	return res;
+}
+
+
 
 #define SWAP_INT(a,b) do { int t; t = a; a = b; b = t; } while (0)
 
@@ -3782,7 +3799,6 @@ sheet_foreach_cell_in_range (Sheet *sheet, CellIterFlags flags,
 	gboolean const ignore_empty = (flags & CELL_ITER_IGNORE_EMPTY) != 0;
 	gboolean ignore;
 	gboolean use_celllist;
-	GSList *celllist = NULL;
 	size_t range_size;
 
 	g_return_val_if_fail (IS_SHEET (sheet), NULL);
@@ -3810,32 +3826,29 @@ sheet_foreach_cell_in_range (Sheet *sheet, CellIterFlags flags,
 		only_existing &&
 		range_size > g_hash_table_size (sheet->cell_hash) + 1000;
 	if (use_celllist) {
-		GHashTableIter hiter;
-		gpointer value;
-		GSList *l;
+		GPtrArray *all_cells;
 		int last_row = -1, last_col = -1;
 		GnmValue *res = NULL;
+		unsigned ui;
 
 		if (gnm_debug_flag ("sheet-foreach"))
 			g_printerr ("Using celllist for area of size %d\n",
 				    (int)range_size);
 
-		g_hash_table_iter_init (&hiter, sheet->cell_hash);
-		while (g_hash_table_iter_next (&hiter, NULL, &value)) {
-			GnmCell *cell = value;
+		all_cells = sheet_cells (sheet);
+
+		for (ui = 0; ui < all_cells->len; ui++) {
+			GnmCell *cell = g_ptr_array_index (all_cells, ui);
+
 			if (cell->pos.col < start_col ||
 			    cell->pos.col > end_col ||
 			    cell->pos.row < start_row ||
 			    cell->pos.row > end_row)
 				continue;
-			celllist = g_slist_prepend (celllist, cell);
-		}
-		celllist = g_slist_sort (celllist, cell_ordering);
 
-		for (l = celllist; l; l = l->next) {
-			iter.cell = l->data;
-			iter.pp.eval.row = iter.cell->pos.row;
-			iter.pp.eval.col = iter.cell->pos.col;
+			iter.cell = cell;
+			iter.pp.eval.row = cell->pos.row;
+			iter.pp.eval.col = cell->pos.col;
 
 			if (iter.pp.eval.row != last_row) {
 				last_row = iter.pp.eval.row;
@@ -3854,8 +3867,8 @@ sheet_foreach_cell_in_range (Sheet *sheet, CellIterFlags flags,
 				continue;
 
 			ignore = (ignore_empty &&
-				  VALUE_IS_EMPTY (iter.cell->value) &&
-				  !gnm_cell_needs_recalc (iter.cell));
+				  VALUE_IS_EMPTY (cell->value) &&
+				  !gnm_cell_needs_recalc (cell));
 			if (ignore)
 				continue;
 
@@ -3864,7 +3877,7 @@ sheet_foreach_cell_in_range (Sheet *sheet, CellIterFlags flags,
 				break;
 		}
 
-		g_slist_free (celllist);
+		g_ptr_array_free (all_cells, TRUE);
 		return res;
 	}
 
@@ -3971,7 +3984,7 @@ cb_sheet_cells_collect (G_GNUC_UNUSED gpointer unused,
 }
 
 /**
- * sheet_cells:
+ * sheet_cell_positions:
  *
  * @sheet: The sheet to find cells in.
  * @comments: If true, include cells with only comments also.
@@ -3981,7 +3994,7 @@ cb_sheet_cells_collect (G_GNUC_UNUSED gpointer unused,
  * Returns: (element-type GnmEvalPos) (transfer full): the newly created array
  **/
 GPtrArray *
-sheet_cells (Sheet *sheet, gboolean comments)
+sheet_cell_positions (Sheet *sheet, gboolean comments)
 {
 	GPtrArray *cells = g_ptr_array_new ();
 
diff --git a/src/sheet.h b/src/sheet.h
index af0b8d2..5a3b5fe 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -165,7 +165,9 @@ GnmValue *sheet_foreach_cell_in_range	(Sheet *sheet, CellIterFlags flags,
 void	    sheet_cell_foreach	 (Sheet const *sheet,
 				  GHFunc callback, gpointer data);
 unsigned    sheet_cells_count	 (Sheet const *sheet);
-GPtrArray  *sheet_cells          (Sheet *sheet, gboolean comments);
+GPtrArray  *sheet_cell_positions (Sheet *sheet, gboolean comments);
+
+GPtrArray  *sheet_cells          (Sheet *sheet);
 
 void        sheet_recompute_spans_for_col     (Sheet *sheet, int col);
 
diff --git a/src/workbook.c b/src/workbook.c
index b44ee36..72a56be 100644
--- a/src/workbook.c
+++ b/src/workbook.c
@@ -594,7 +594,7 @@ workbook_cells (Workbook *wb, gboolean comments, GnmSheetVisibility vis)
 		if (sheet->visibility > vis)
 			continue;
 
-		scells = sheet_cells (sheet, comments);
+		scells = sheet_cell_positions (sheet, comments);
 		g_ptr_array_set_size (cells, oldlen + scells->len);
 		memcpy (&g_ptr_array_index (cells, oldlen),
 			&g_ptr_array_index (scells, 0),



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