[gnumeric] ods: share expressions also during load.



commit 3da696f71f1e8c0ae237f0ca884409061f6be9bf
Author: Morten Welinder <terra gnome org>
Date:   Tue Mar 13 13:32:39 2012 -0400

    ods: share expressions also during load.
    
    This is needed because ods lacks a concept of shared expressions.

 ChangeLog                            |    7 +++++++
 NEWS                                 |    1 +
 plugins/excel/ms-chart.c             |   13 ++++++++++---
 plugins/openoffice/ChangeLog         |    5 +++++
 plugins/openoffice/openoffice-read.c |    9 +++++++++
 src/expr.c                           |    8 ++++++++
 src/expr.h                           |    1 +
 src/workbook.c                       |    5 +++++
 8 files changed, 46 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 44848d4..7e98d62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-03-13  Morten Welinder  <terra gnome org>
+
+	* src/workbook.c (workbook_share_expressions): Add sharing debug
+	code.
+
+	* src/expr.c (gnm_expr_sharer_report): New function.
+
 2012-03-12  Morten Welinder  <terra gnome org>
 
 	* src/expr.c (do_expr_as_string): Set a precedence for set.
diff --git a/NEWS b/NEWS
index 573b388..e1cdccf 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,7 @@ Morten:
 	* Export paper size to xls.
 	* Improve xls export of chart legends.  [Part of #671845]
 	* Export sets to xls.
+	* Lower memory usage for ods load.  [#671863]
 
 --------------------------------------------------------------------------
 Gnumeric 1.11.2
diff --git a/plugins/excel/ms-chart.c b/plugins/excel/ms-chart.c
index ea6e56c..a9c4f9d 100644
--- a/plugins/excel/ms-chart.c
+++ b/plugins/excel/ms-chart.c
@@ -3992,7 +3992,10 @@ chart_write_AREAFORMAT (XLChartWriteState *s, GOStyle const *style, gboolean dis
 			break;
 		}
 
-		if (style->fill.auto_type && style->fill.auto_fore && style->fill.auto_back && !disable_auto)
+		/* As we set only one of auto_fore and auto_back when reading,
+		 * we don't need to have both TRUE to set the auto flag here.
+		 * See bug #671845 */
+		if (style->fill.auto_type && (style->fill.auto_fore || style->fill.auto_back) && !disable_auto)
 			flags |= 1;
 		if (style->fill.invert_if_negative)
 			flags |= 2;
@@ -4038,7 +4041,7 @@ chart_write_LINEFORMAT (XLChartWriteState *s, GOStyleLine const *lstyle,
 			w = 2;	/* wide */
 		/* seems that excel understand auto as solid, so if pattern is not solid
 		   do not set the auto flag, see #605043 */
-		flags |= (lstyle->auto_color && pat > 0)? 1: 0;
+		flags |= (lstyle->auto_color && pat == 0)? 1: 0;
 	} else {
 		color_index = chart_write_color (s, data, 0);
 		if (clear_lines_for_null) {
@@ -5580,7 +5583,11 @@ ms_excel_chart_write (ExcelWriteState *ewb, SheetObject *so)
 
 #warning be smart about singletons and titles
 	data = ms_biff_put_len_next (state.bp, BIFF_CHART_chart, 4*4);
-	chart_write_position (&state, state.chart, data, XL_POS_LOW, XL_POS_LOW);
+//	chart_write_position (&state, state.chart, data, XL_POS_LOW, XL_POS_LOW);
+	GSF_LE_SET_GUINT32 (data + 0, (int) (state.root_view->allocation.x * 65535.));
+	GSF_LE_SET_GUINT32 (data + 4, (int) (state.root_view->allocation.y * 65535.));
+	GSF_LE_SET_GUINT32 (data + 8, (int) (state.root_view->allocation.w * 65535.));
+	GSF_LE_SET_GUINT32 (data + 12, (int) (state.root_view->allocation.h * 65535.));
 	ms_biff_put_commit (state.bp);
 
 	chart_write_BEGIN (&state);
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 7b2403f..46ebd64 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,8 @@
+2012-03-13  Morten Welinder  <terra gnome org>
+
+	* openoffice-read.c (oo_expr_parse_str): Share expressions because
+	ODS sucks in that regard.
+
 2012-03-12  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-write.c (odf_write_one_axis_grid): write style name
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 78274da..543ab9b 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -312,6 +312,7 @@ typedef struct {
 	GnmComment      *cell_comment;
 	GnmCell         *curr_cell;
 	GSList          *span_style_stack;
+	GnmExprSharer   *sharer;
 
 	int		 col_inc, row_inc;
 	gboolean	 content_is_simple;
@@ -1643,6 +1644,7 @@ oo_expr_parse_str (GsfXMLIn *xin, char const *str,
 		   GnmParsePos const *pp, GnmExprParseFlags flags,
 		   OOFormula type)
 {
+	OOParseState *state = (OOParseState *)xin->user_state;
 	GnmExprTop const *texpr;
 	GnmParseError  perr;
 
@@ -1663,6 +1665,10 @@ oo_expr_parse_str (GsfXMLIn *xin, char const *str,
 				    str, perr.err->message);
 	}
 	parse_error_free (&perr);
+
+	if (texpr)
+		texpr = gnm_expr_sharer_share (state->sharer, texpr);
+
 	return texpr;
 }
 
@@ -10617,6 +10623,7 @@ openoffice_file_open (G_GNUC_UNUSED GOFileOpener const *fo, GOIOContext *io_cont
 	state.pos.eval.col	= -1;
 	state.pos.eval.row	= -1;
 	state.cell_comment      = NULL;
+	state.sharer = gnm_expr_sharer_new ();
 	state.chart.i_plot_styles[OO_CHART_STYLE_PLOTAREA] = NULL;
 	state.chart.i_plot_styles[OO_CHART_STYLE_SERIES] = NULL;
 	state.styles.sheet = g_hash_table_new_full (g_str_hash, g_str_equal,
@@ -10852,6 +10859,8 @@ openoffice_file_open (G_GNUC_UNUSED GOFileOpener const *fo, GOIOContext *io_cont
 	g_hash_table_destroy (state.chart.arrow_markers);
 	g_slist_free_full (state.span_style_stack, g_free);
 	g_object_unref (contents);
+	gnm_expr_sharer_report (state.sharer);
+	gnm_expr_sharer_destroy (state.sharer);
 
 	g_object_unref (zip);
 
diff --git a/src/expr.c b/src/expr.c
index 6b7e6d0..13488bf 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -2805,6 +2805,14 @@ gnm_expr_sharer_share (GnmExprSharer *es, GnmExprTop const *texpr)
 	return texpr;
 }
 
+void
+gnm_expr_sharer_report (GnmExprSharer *es)
+{
+	g_printerr ("Expressions in: %d\n", es->nodes_in);
+	g_printerr ("Expressions stored: %d\n", es->nodes_stored);
+	g_printerr ("Expressions killed: %d\n", es->nodes_killed);
+}
+
 /***************************************************************************/
 
 GnmExprTop const *
diff --git a/src/expr.h b/src/expr.h
index 84c295b..bc1b164 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -192,6 +192,7 @@ void	  gnm_expr_top_as_gstring (GnmExprTop const *texpr,
 GnmExprSharer *   gnm_expr_sharer_new  (void);
 void              gnm_expr_sharer_destroy (GnmExprSharer *es);
 GnmExprTop const *gnm_expr_sharer_share (GnmExprSharer *es, GnmExprTop const *texpr);
+void              gnm_expr_sharer_report (GnmExprSharer *es);
 
 /*****************************************************************************/
 
diff --git a/src/workbook.c b/src/workbook.c
index f548a94..edf1281 100644
--- a/src/workbook.c
+++ b/src/workbook.c
@@ -561,6 +561,11 @@ workbook_share_expressions (Workbook *wb, gboolean freeit)
 		}
 	});
 
+	if (gnm_debug_flag ("expr-sharer")) {
+		g_printerr ("Sharing report for %s\n", go_doc_get_uri (GO_DOC (wb)));
+		gnm_expr_sharer_report (es);
+	}
+
 	if (freeit) {
 		gnm_expr_sharer_destroy (es);
 		es = NULL;



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