[gnumeric] ColRow: eliminate col/row info that is identical to the default.



commit 92c248c9e0f6b3b0fb7bca3c9d0d0e9eca6b294a
Author: Morten Welinder <terra gnome org>
Date:   Fri May 6 14:58:47 2011 -0400

    ColRow: eliminate col/row info that is identical to the default.
    
    This avoids slowdowns in the gui and creation of large xls files.

 ChangeLog         |   11 ++++++++---
 NEWS              |    1 +
 src/colrow.c      |    3 +++
 src/sheet-style.c |    2 ++
 src/sheet.c       |   39 +++++++++++++++++++++++++++++++++++++++
 src/sheet.h       |    2 ++
 6 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index affa809..675e6af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,15 @@
-2011-05-06  Andreas J. Guelzow <aguelzow pyrshep ca>
+2011-05-06  Morten Welinder  <terra gnome org>
 
-	* src/func.c (function_dump_defs): write ellipsis in syntax
+	* src/sheet.c (sheet_colrow_optimize): New function.
+
+	* src/sheet-style.c (sheet_style_optimize): Also optimize colrows.
+
+	* src/colrow.c (colrow_set_visibility_list): If making visible,
+	optimize colrows.
 
 2011-05-06  Andreas J. Guelzow <aguelzow pyrshep ca>
 
-	* src/func.c (function_def_count_args): special case INDEX
+	* src/func.c (function_dump_defs): write ellipsis in syntax
 
 2011-05-05  Morten Welinder  <terra gnome org>
 
diff --git a/NEWS b/NEWS
index 0102c4e..bf40791 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Morten:
 	* Plug leak.
 	* Fix minor problem reading old xls objects.
 	* Reduce memory usage when new glib is used.  [#644197]
+	* Eliminate col/row infos that are identical to the default.  [#155003]
 
 Urmas:
 	* Initial support for Works files.  [#647492]
diff --git a/src/colrow.c b/src/colrow.c
index cc02281..6930281 100644
--- a/src/colrow.c
+++ b/src/colrow.c
@@ -980,6 +980,9 @@ colrow_set_visibility_list (Sheet *sheet, gboolean is_cols,
 				       info->first, info->last);
 	}
 
+	if (visible)
+		sheet_colrow_optimize (sheet);
+
 	if (is_cols)
 		sheet_queue_respan (sheet, 0, gnm_sheet_get_last_row (sheet));
 	if (list != NULL)
diff --git a/src/sheet-style.c b/src/sheet-style.c
index 00054ab..40e47e5 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -2890,6 +2890,8 @@ sheet_style_optimize (Sheet *sheet)
 	if (gnm_debug_flag ("no-style-optimize"))
 		return;
 
+	sheet_colrow_optimize (sheet);
+
 	data.ss = gnm_sheet_get_size (sheet);
 	data.recursion = TRUE;
 
diff --git a/src/sheet.c b/src/sheet.c
index 5fdd226..b91627c 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -3419,6 +3419,45 @@ sheet_colrow_get_default (Sheet const *sheet, gboolean is_cols)
 	return is_cols ? &sheet->cols.default_style : &sheet->rows.default_style;
 }
 
+static void
+sheet_colrow_optimize1 (int max, ColRowCollection *collection)
+{
+	int i;
+
+	for (i = 0; i < max; i += COLROW_SEGMENT_SIZE) {
+		ColRowSegment *segment = COLROW_GET_SEGMENT (collection, i);
+		int j;
+		gboolean any = FALSE;
+
+		if (!segment)
+			continue;
+		for (j = 0; j < COLROW_SEGMENT_SIZE; j++) {
+			ColRowInfo *info = segment->info[j];
+			if (!info)
+				continue;
+			if (colrow_equal (&collection->default_style, info)) {
+				colrow_free (info);
+				segment->info[j] = NULL;
+			} else
+				any = TRUE;
+		}
+
+		if (!any) {
+			g_free (segment);
+			COLROW_GET_SEGMENT (collection, i) = NULL;
+		}
+	}
+}
+
+void
+sheet_colrow_optimize (Sheet *sheet)
+{
+	g_return_if_fail (IS_SHEET (sheet));
+
+	sheet_colrow_optimize1 (gnm_sheet_get_max_cols (sheet), &sheet->cols);
+	sheet_colrow_optimize1 (gnm_sheet_get_max_rows (sheet), &sheet->rows);
+}
+
 /**
  * sheet_col_get:
  *
diff --git a/src/sheet.h b/src/sheet.h
index 374d5c1..d0307bf 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -184,6 +184,8 @@ int	    sheet_find_boundary_vertical   (Sheet *sheet, int move_col, int row,
 ColRowInfo const *sheet_colrow_get_default (Sheet const *sheet,
 					    gboolean is_cols);
 
+void        sheet_colrow_optimize          (Sheet *sheet);
+
 /* Returns a pointer to a ColRowInfo: existing or NULL */
 ColRowInfo *sheet_col_get                 (Sheet const *sheet, int col);
 ColRowInfo *sheet_row_get                 (Sheet const *sheet, int row);



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