[gnumeric] Cell: use less memory.



commit 31cf7d3b935159104be8b7be4f115f26957044bc
Author: Morten Welinder <terra gnome org>
Date:   Wed Mar 14 20:02:47 2012 -0400

    Cell: use less memory.

 ChangeLog        |   12 ++++++++++
 NEWS             |    1 +
 src/cell.c       |    3 +-
 src/cell.h       |    1 -
 src/cellspan.c   |   24 +++++++++++++--------
 src/dependent.c  |    4 +-
 src/item-grid.c  |    6 ++--
 src/print-cell.c |    6 ++--
 src/sheet.c      |   60 +++++++++++++++++++++++++++++++++++------------------
 src/sheet.h      |    1 +
 10 files changed, 77 insertions(+), 41 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7e98d62..68e1acc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-03-14  Morten Welinder  <terra gnome org>
+
+	* src/cell.h (struct _GnmCell): remove row_info pointers.  All
+	users fixed.
+
+	* src/sheet.c (sheet_cell_queue_respan): New function.
+	(cb_re_render_formulas, cb_clear_rendered_cells): Use
+	sheet_cell_queue_respan.
+
+	* src/dependent.c (gnm_cell_eval_content): Use
+	sheet_cell_queue_respan.
+
 2012-03-13  Morten Welinder  <terra gnome org>
 
 	* src/workbook.c (workbook_share_expressions): Add sharing debug
diff --git a/NEWS b/NEWS
index 109cd49..f868b94 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,7 @@ Morten:
 	* Export sets to xls.
 	* Lower memory usage for ods load.  [#671863]
 	* Improve test suite.
+	* Lower per-cell memory usage.
 
 --------------------------------------------------------------------------
 Gnumeric 1.11.2
diff --git a/src/cell.c b/src/cell.c
index 27a5aab..52f4d1a 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -65,8 +65,7 @@ gnm_cell_cleanout (GnmCell *cell)
 
 	gnm_cell_unrender (cell);
 
-	if (cell->row_info != NULL)
-		cell->row_info->needs_respan = TRUE;
+	sheet_cell_queue_respan (cell);
 }
 
 /****************************************************************************/
diff --git a/src/cell.h b/src/cell.h
index 7fda4d4..152c4c1 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -25,7 +25,6 @@ struct _GnmCell {
 
 	/* Mandatory state information */
 	GnmCellPos     pos;
-	ColRowInfo    *row_info;
 
 	GnmValue      *value;	/* computed or entered (Must be non NULL) */
 };
diff --git a/src/cellspan.c b/src/cellspan.c
index ecb7b80..94aa9da 100644
--- a/src/cellspan.c
+++ b/src/cellspan.c
@@ -73,13 +73,14 @@ void
 cell_register_span (GnmCell const *cell, int left, int right)
 {
 	ColRowInfo *ri;
-	int col, i;
+	int col, row, i;
 
 	g_return_if_fail (cell != NULL);
 	g_return_if_fail (left <= right);
 
-	ri = cell->row_info;
 	col = cell->pos.col;
+	row = cell->pos.row;
+	ri = sheet_row_get (cell->base.sheet, row);
 
 	if (left == right)
 		return;
@@ -122,14 +123,17 @@ span_remove (G_GNUC_UNUSED gpointer key, gpointer value,
 void
 cell_unregister_span (GnmCell const * const cell)
 {
+	ColRowInfo *ri;
+
 	g_return_if_fail (cell != NULL);
-	g_return_if_fail (cell->row_info != NULL);
 
-	if (cell->row_info->spans == NULL)
+	ri = sheet_row_get (cell->base.sheet, cell->pos.row);
+
+	if (ri->spans == NULL)
 		return;
 
-	g_hash_table_foreach_remove (cell->row_info->spans,
-		&span_remove, (gpointer)cell);
+	g_hash_table_foreach_remove (ri->spans,
+				     &span_remove, (gpointer)cell);
 }
 
 /*
@@ -170,14 +174,16 @@ row_span_get (ColRowInfo const * const ri, int const col)
 static inline gboolean
 cellspan_is_empty (int col, GnmCell const *ok_span_cell)
 {
-	CellSpanInfo const *span = row_span_get (ok_span_cell->row_info, col);
+	Sheet *sheet = ok_span_cell->base.sheet;
+	int row = ok_span_cell->pos.row;
+	ColRowInfo *ri = sheet_row_get (sheet, row);
+	CellSpanInfo const *span = row_span_get (ri, col);
 	GnmCell const *tmp;
 
 	if (span != NULL && span->cell != ok_span_cell)
 		return FALSE;
 
-	tmp = sheet_cell_get (ok_span_cell->base.sheet,
-		col, ok_span_cell->pos.row);
+	tmp = sheet_cell_get (sheet, col, row);
 
 	/* FIXME : cannot use gnm_cell_is_empty until expressions can span.
 	 * because cells with expressions start out with value Empty
diff --git a/src/dependent.c b/src/dependent.c
index abbcbde..394eb8b 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -1575,8 +1575,8 @@ iterate :
 			gboolean was_string = had_value && (VALUE_IS_STRING (cell->value) || VALUE_IS_ERROR (cell->value));
 			gboolean is_string = VALUE_IS_STRING (v) || VALUE_IS_ERROR (v);
 
-			if ((was_string || is_string) && cell->row_info)
-				cell->row_info->needs_respan = TRUE;
+			if ((was_string || is_string))
+				sheet_cell_queue_respan (cell);
 
 			if (had_value)
 				value_release (cell->value);
diff --git a/src/item-grid.c b/src/item-grid.c
index aafcc9f..e502a25 100644
--- a/src/item-grid.c
+++ b/src/item-grid.c
@@ -239,7 +239,7 @@ item_grid_draw_merged_range (cairo_t *cr, ItemGrid *ig,
 	gboolean show_function_cell_markers = wbv->show_function_cell_markers;
 	gboolean show_extension_markers = wbv->show_extension_markers;
 	Sheet const *sheet  = sv->sheet;
-	GnmCell  const *cell   = sheet_cell_get (sheet, range->start.col, range->start.row);
+	GnmCell const *cell = sheet_cell_get (sheet, range->start.col, range->start.row);
 	int const dir = sheet->text_is_rtl ? -1 : 1;
 
 	/* load style from corner which may not be visible */
@@ -304,10 +304,10 @@ item_grid_draw_merged_range (cairo_t *cr, ItemGrid *ig,
 			view->end.row+1, range->end.row+1);
 
 	if (cell != NULL) {
-		ColRowInfo const * const ri = cell->row_info;
+		ColRowInfo *ri = sheet_row_get (sheet, range->start.row);
 
 		if (ri->needs_respan)
-			row_calc_spans ((ColRowInfo *)ri, cell->pos.row, sheet);
+			row_calc_spans (ri, cell->pos.row, sheet);
 
 		if (dir > 0) {
 			if (show_function_cell_markers)
diff --git a/src/print-cell.c b/src/print-cell.c
index 506e825..c0565ae 100644
--- a/src/print-cell.c
+++ b/src/print-cell.c
@@ -215,7 +215,7 @@ print_merged_range_gtk (cairo_t *context,
 {
 	double l, r, t, b;
 	int last;
-	GnmCell  const *cell  = sheet_cell_get (sheet, range->start.col, range->start.row);
+	GnmCell  const *cell = sheet_cell_get (sheet, range->start.col, range->start.row);
 	int const dir = sheet->text_is_rtl ? -1 : 1;
 
 	/* load style from corner which may not be visible */
@@ -265,10 +265,10 @@ print_merged_range_gtk (cairo_t *context,
 			view->end.row+1, range->end.row+1);
 
 	if (cell != NULL) {
-		ColRowInfo const * const ri = cell->row_info;
+		ColRowInfo *ri = sheet_row_get (sheet, range->start.row);
 
 		if (ri->needs_respan)
-			row_calc_spans ((ColRowInfo *)ri, cell->pos.row, sheet);
+			row_calc_spans (ri, cell->pos.row, sheet);
 
 		if (sheet->text_is_rtl)
 			print_cell_gtk (cell, context,
diff --git a/src/sheet.c b/src/sheet.c
index 9d19388..9241711 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -168,8 +168,7 @@ cb_re_render_formulas (G_GNUC_UNUSED gpointer unused,
 {
 	if (gnm_cell_has_expr (cell)) {
 		gnm_cell_unrender (cell);
-		if (cell->row_info != NULL)
-			cell->row_info->needs_respan = TRUE;
+		sheet_cell_queue_respan (cell);
 	}
 }
 
@@ -322,7 +321,7 @@ static void
 cb_clear_rendered_cells (gpointer ignored, GnmCell *cell)
 {
 	if (gnm_cell_get_rendered_value (cell) != NULL) {
-		cell->row_info->needs_respan = TRUE;
+		sheet_cell_queue_respan (cell);
 		gnm_cell_unrender (cell);
 	}
 }
@@ -1429,28 +1428,32 @@ static void
 sheet_redraw_cell (GnmCell const *cell)
 {
 	CellSpanInfo const * span;
-	int start_col, end_col;
+	int start_col, end_col, row;
 	GnmRange const *merged;
+	Sheet *sheet;
+	ColRowInfo *ri;
 
 	g_return_if_fail (cell != NULL);
 
-	merged = gnm_sheet_merge_is_corner (cell->base.sheet, &cell->pos);
+	sheet = cell->base.sheet;
+	merged = gnm_sheet_merge_is_corner (sheet, &cell->pos);
 	if (merged != NULL) {
-		SHEET_FOREACH_CONTROL (cell->base.sheet, view, control,
+		SHEET_FOREACH_CONTROL (sheet, view, control,
 			sc_redraw_range (control, merged););
 		return;
 	}
 
+	row = cell->pos.row;
 	start_col = end_col = cell->pos.col;
-	span = row_span_get (cell->row_info, start_col);
+	ri = sheet_row_get (sheet, row);
+	span = row_span_get (ri, start_col);
 
 	if (span) {
 		start_col = span->left;
 		end_col = span->right;
 	}
 
-	sheet_redraw_partial_row (cell->base.sheet, cell->pos.row,
-				  start_col, end_col);
+	sheet_redraw_partial_row (sheet, row, start_col, end_col);
 }
 
 static void
@@ -1458,14 +1461,19 @@ sheet_cell_calc_span (GnmCell *cell, GnmSpanCalcFlags flags)
 {
 	CellSpanInfo const * span;
 	int left, right;
-	int min_col, max_col;
+	int min_col, max_col, row;
 	gboolean render = (flags & GNM_SPANCALC_RE_RENDER) != 0;
 	gboolean const resize = (flags & GNM_SPANCALC_RESIZE) != 0;
 	gboolean existing = FALSE;
 	GnmRange const *merged;
+	Sheet *sheet;
+	ColRowInfo *ri;
 
 	g_return_if_fail (cell != NULL);
 
+	sheet = cell->base.sheet;
+	row = cell->pos.row;
+
 	/* Render & Size any unrendered cells */
 	if ((flags & GNM_SPANCALC_RENDER) && gnm_cell_get_rendered_value (cell) == NULL)
 		render = TRUE;
@@ -1481,7 +1489,8 @@ sheet_cell_calc_span (GnmCell *cell, GnmSpanCalcFlags flags)
 	}
 
 	/* Is there an existing span ? clear it BEFORE calculating new one */
-	span = row_span_get (cell->row_info, cell->pos.col);
+	ri = sheet_row_get (sheet, row);
+	span = row_span_get (ri, cell->pos.col);
 	if (span != NULL) {
 		GnmCell const * const other = span->cell;
 
@@ -1506,7 +1515,7 @@ sheet_cell_calc_span (GnmCell *cell, GnmSpanCalcFlags flags)
 	} else
 		min_col = max_col = cell->pos.col;
 
-	merged = gnm_sheet_merge_is_corner (cell->base.sheet, &cell->pos);
+	merged = gnm_sheet_merge_is_corner (sheet, &cell->pos);
 	if (NULL != merged) {
 		if (existing) {
 			if (min_col > merged->start.col)
@@ -1539,8 +1548,7 @@ sheet_cell_calc_span (GnmCell *cell, GnmSpanCalcFlags flags)
 			cell_register_span (cell, left, right);
 	}
 
-	sheet_redraw_partial_row (cell->base.sheet,
-		cell->pos.row, min_col, max_col);
+	sheet_redraw_partial_row (sheet, row, min_col, max_col);
 }
 
 /**
@@ -2055,6 +2063,7 @@ cb_sheet_get_extent (gpointer ignored, gpointer value, gpointer data)
 {
 	GnmCell const *cell = (GnmCell const *) value;
 	struct sheet_extent_data *res = data;
+	Sheet *sheet = cell->base.sheet;
 
 	if (res->ignore_empties && gnm_cell_is_empty (cell))
 		return;
@@ -2075,13 +2084,14 @@ cb_sheet_get_extent (gpointer ignored, gpointer value, gpointer data)
 	/* Cannot span AND merge */
 	if (gnm_cell_is_merged (cell)) {
 		GnmRange const *merged =
-			gnm_sheet_merge_is_corner (cell->base.sheet, &cell->pos);
+			gnm_sheet_merge_is_corner (sheet, &cell->pos);
 		res->range = range_union (&res->range, merged);
 	} else {
 		CellSpanInfo const *span;
-		if (cell->row_info->needs_respan)
-			row_calc_spans (cell->row_info, cell->pos.row, cell->base.sheet);
-		span = row_span_get (cell->row_info, cell->pos.col);
+		ColRowInfo *ri = sheet_row_get (sheet, cell->pos.row);
+		if (ri->needs_respan)
+			row_calc_spans (ri, cell->pos.row, sheet);
+		span = row_span_get (ri, cell->pos.col);
 		if (NULL != span) {
 			if (res->range.start.col > span->left)
 				res->range.start.col = span->left;
@@ -3859,7 +3869,7 @@ sheet_cell_add_to_hash (Sheet *sheet, GnmCell *cell)
 	cell->base.flags |= GNM_CELL_IN_SHEET_LIST;
 	/* NOTE :
 	 *   fetching the col/row here serve 3 functions
-	 *   1) The obvious.  Storing the ptr in the cell.
+	 *   1) obsolete: we used to store the pointer in the cell
 	 *   2) Expanding col/row.max_used
 	 *   3) Creating an entry in the COLROW_SEGMENT.  Lots and lots of
 	 *	things use those to help limit iteration
@@ -3868,8 +3878,8 @@ sheet_cell_add_to_hash (Sheet *sheet, GnmCell *cell)
 	 * ensure that 2,3 still happen.  Alot will need rewriting to avoid
 	 * these requirements.
 	 **/
-	(void) sheet_col_fetch (sheet, cell->pos.col);
-	cell->row_info   = sheet_row_fetch (sheet, cell->pos.row);
+	(void)sheet_col_fetch (sheet, cell->pos.col);
+	(void)sheet_row_fetch (sheet, cell->pos.row);
 
 	gnm_cell_unrender (cell);
 
@@ -5869,6 +5879,14 @@ sheet_queue_respan (Sheet const *sheet, int start_row, int end_row)
 		cb_queue_respan, NULL);
 }
 
+void
+sheet_cell_queue_respan (GnmCell *cell)
+{
+	ColRowInfo *ri = sheet_row_get (cell->base.sheet, cell->pos.row);
+	ri->needs_respan = TRUE;
+}
+
+
 /**
  * sheet_get_comment :
  * @sheet : #Sheet const *
diff --git a/src/sheet.h b/src/sheet.h
index 9aa5518..c06198c 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -337,6 +337,7 @@ GOUndo *     sheet_apply_style_undo (GnmSheetRange *sr,
 				     GnmStyle      *style);
 void	     sheet_apply_border	    (Sheet  *sheet, GnmRange const *range, GnmBorder **borders);
 void	     sheet_queue_respan     (Sheet const *sheet, int start_row, int end_row);
+void         sheet_cell_queue_respan (GnmCell *cell);
 void	     sheet_range_calc_spans (Sheet *sheet, GnmRange const *r, GnmSpanCalcFlags flags);
 
 void	     sheet_set_outline_direction (Sheet *sheet, gboolean is_cols);



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