[gnumeric] speed up writing of odf files
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] speed up writing of odf files
- Date: Tue, 16 Jun 2009 01:44:25 -0400 (EDT)
commit c4e27d2de2a977bc405a43738eb58c8a565b07a7
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Mon Jun 15 23:43:52 2009 -0600
speed up writing of odf files
2009-06-15 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/mstyle.c (gnm_style_equal): check first for pointer equality
2009-06-15 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (cell_styles_free): deleted
(odf_compare_style): deleted
(odf_find_style): just look in the hash. remove
unnecessary arguments and change all callers
(odf_save_automatic_character_styles): deleted
(odf_save_this_style): write an individual style and
save it in the hash
(odf_write_character_styles): call odf_save_this_style
for each style
ChangeLog | 4 +
plugins/openoffice/ChangeLog | 14 ++++-
plugins/openoffice/openoffice-write.c | 124 ++++++--------------------------
src/mstyle.c | 4 +-
4 files changed, 43 insertions(+), 103 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a43fbeb..cf6278f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-06-15 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/mstyle.c (gnm_style_equal): check first for pointer equality
+
2009-06-14 Morten Welinder <terra gnome org>
Implement New-From-Template (#303657):
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index de6cb98..45b3c3f 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,15 @@
+2009-06-15 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-write.c (cell_styles_free): deleted
+ (odf_compare_style): deleted
+ (odf_find_style): just look in the hash. remove
+ unnecessary arguments and change all callers
+ (odf_save_automatic_character_styles): deleted
+ (odf_save_this_style): write an individual style and
+ save it in the hash
+ (odf_write_character_styles): call odf_save_this_style
+ for each style
+
2009-06-10 Morten Welinder <terra gnome org>
* openoffice-read.c (oo_load_convention): Mark '^'
@@ -6,7 +18,7 @@
2009-06-10 Andreas J. Guelzow <aguelzow pyrshep ca>
- openoffice-write.c (odf_write_content): export print area to ODF
+ * openoffice-write.c (odf_write_content): export print area to ODF
2009-06-09 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index de060c4..5f2c42f 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -95,7 +95,7 @@ typedef struct {
GnmConventions *conv;
GSList *row_styles;
GSList *col_styles;
- GSList *cell_styles;
+ GHashTable *cell_styles;
GHashTable *xl_styles;
GHashTable *xl_styles_neg;
GHashTable *xl_styles_zero;
@@ -108,11 +108,6 @@ typedef struct {
typedef struct {
char *name;
- GnmStyle const *style;
-} cell_styles_t;
-
-typedef struct {
- char *name;
ColRowInfo const *ci;
} col_row_styles_t;
@@ -505,16 +500,6 @@ xl_find_conditional_format (GnmOOExport *state, GOFormat const *format)
}
static void
-cell_styles_free (gpointer data)
-{
- cell_styles_t *style = data;
-
- g_free (style->name);
- gnm_style_unref (style->style);
- g_free (style);
-}
-
-static void
odf_write_table_styles (GnmOOExport *state)
{
int i;
@@ -542,15 +527,6 @@ equal_style (GnmStyle const *that, GnmStyle const *this)
return gnm_style_equal (that, this);
}
-static gint
-odf_compare_style (gconstpointer a, gconstpointer b)
-{
- cell_styles_t const *old_style = a;
- GnmStyle const *new_style = b;
-
- return !equal_style (new_style, old_style->style);
-}
-
static char *
odf_get_border_format (GnmBorder *border)
{
@@ -994,30 +970,16 @@ odf_write_style (GnmOOExport *state, GnmStyle const *style, gboolean is_default)
#undef BORDERSTYLE
static const char*
-odf_find_style (GnmOOExport *state, GnmStyle const *style, gboolean write, gboolean is_default)
+odf_find_style (GnmOOExport *state, GnmStyle const *style)
{
- cell_styles_t *new_style;
- GSList *found = g_slist_find_custom (state->cell_styles, style, odf_compare_style);
+ char const *found = g_hash_table_lookup (state->cell_styles, style);
- if (found) {
- new_style = found->data;
- return new_style->name;
- } else {
- if (write) {
- new_style = g_new0 (cell_styles_t,1);
- new_style->style = style;
- gnm_style_ref (style);
- new_style->name = g_strdup_printf ("ACELL-%i", g_slist_length (state->cell_styles));
- state->cell_styles = g_slist_prepend (state->cell_styles, new_style);
- odf_start_style (state->xml, new_style->name, "table-cell");
- odf_write_style (state, new_style->style, is_default);
- gsf_xml_out_end_element (state->xml); /* </style:style */
- return new_style->name;
- } else {
- g_warning("We forgot to export a required style!");
- return "Missing-Style";
- }
+ if (found == NULL) {
+ g_warning("We forgot to export a required style!");
+ return "Missing-Style";
}
+
+ return found;
}
static gint
@@ -1104,53 +1066,13 @@ odf_find_col_style (GnmOOExport *state, ColRowInfo const *ci, gboolean write)
}
static void
-odf_save_automatic_character_styles (GnmOOExport *state)
+odf_save_this_style (GnmStyle *style, G_GNUC_UNUSED gconstpointer dummy, GnmOOExport *state)
{
- /* We have to figure out which automatic styles we need */
- /* This is really annoying since we have to scan through */
- /* all cells. If we could store these styles in styles.xml */
- /* we could create them as we need them, but these styles */
- /* have to go into the beginning of content.xml. */
- int j;
-
- for (j = 0; j < workbook_sheet_count (state->wb); j++) {
- Sheet const *sheet = workbook_sheet_by_index (state->wb, j);
- int max_cols = gnm_sheet_get_max_cols (sheet);
- int max_rows = gnm_sheet_get_max_rows (sheet);
- GnmStyle **col_styles = g_new (GnmStyle *, max_cols);
- GnmRange extent;
- int i, col, row;
- extent = sheet_get_extent (sheet, FALSE);
- sheet_style_get_extent (sheet, &extent, col_styles);
-
- for (i = 0; i < max_cols; i++)
- if (col_styles[i] != NULL)
- odf_find_style (state, col_styles[i], TRUE, FALSE);
-
- /* include collapsed or hidden cols and rows */
- for (i = max_rows ; i-- > extent.end.row ; )
- if (!colrow_is_empty (sheet_row_get (sheet, i))) {
- extent.end.row = i;
- break;
- }
- for (i = max_cols ; i-- > extent.end.col ; )
- if (!colrow_is_empty (sheet_col_get (sheet, i))) {
- extent.end.col = i;
- break;
- }
-
- for (row = extent.start.row; row <= extent.end.row; row++) {
- for (col = extent.start.col; col <= extent.end.col; col++) {
- GnmStyle const *style;
- style = sheet_style_get (sheet, col, row);
- if (style != NULL)
- odf_find_style (state, style, TRUE, FALSE);
- }
- }
- g_free (col_styles);
- }
-
- return;
+ char *name = g_strdup_printf ("ACELL-%p", style);
+ g_hash_table_insert (state->cell_styles, style, name);
+ odf_start_style (state->xml, name, "table-cell");
+ odf_write_style (state, style, FALSE);
+ gsf_xml_out_end_element (state->xml); /* </style:style */
}
static void
@@ -1246,14 +1168,15 @@ odf_write_character_styles (GnmOOExport *state)
gsf_xml_out_end_element (state->xml); /* </style:text-properties> */
gsf_xml_out_end_element (state->xml); /* </style:style> */
- if (state->default_style != NULL)
- odf_find_style (state, state->default_style, TRUE, TRUE);
if (state->row_default != NULL)
odf_find_row_style (state, state->row_default, TRUE);
if (state->column_default != NULL)
odf_find_col_style (state, state->column_default, TRUE);
- odf_save_automatic_character_styles (state);
+ for (i = 0; i < workbook_sheet_count (state->wb); i++)
+ sheet_style_foreach (workbook_sheet_by_index (state->wb, i),
+ (GHFunc) odf_save_this_style,
+ state);
}
static void
@@ -1412,7 +1335,7 @@ odf_write_empty_cell (GnmOOExport *state, int *num, GnmStyle const *style)
TABLE "number-columns-repeated",
*num);
if (style != NULL) {
- char const * name = odf_find_style (state, style, FALSE, FALSE);
+ char const * name = odf_find_style (state, style);
if (name != NULL)
gsf_xml_out_add_cstr (state->xml,
TABLE "style-name", name);
@@ -1462,7 +1385,7 @@ odf_write_cell (GnmOOExport *state, GnmCell *cell, GnmRange const *merge_range,
GnmStyle const *style = gnm_cell_get_style (cell);
if (style) {
- char const * name = odf_find_style (state, style, FALSE, FALSE);
+ char const * name = odf_find_style (state, style);
if (name != NULL)
gsf_xml_out_add_cstr (state->xml,
TABLE "style-name", name);
@@ -1612,7 +1535,7 @@ write_col_style (GnmOOExport *state, GnmStyle *col_style, ColRowInfo const *ci,
char const * name;
if (col_style != NULL) {
- name = odf_find_style (state, col_style, FALSE, FALSE);
+ name = odf_find_style (state, col_style);
if (name != NULL)
gsf_xml_out_add_cstr (state->xml,
TABLE "default-cell-style-name", name);
@@ -2270,7 +2193,8 @@ openoffice_file_save_real (GOFileSaver const *fs, IOContext *ioc,
state.wbv = wbv;
state.wb = wb_view_get_workbook (wbv);
state.conv = odf_expr_conventions_new ();
- state.cell_styles = NULL;
+ state.cell_styles = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL, (GDestroyNotify) g_free);
state.xl_styles = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free, (GDestroyNotify) g_free);
state.xl_styles_neg = g_hash_table_new_full (g_str_hash, g_str_equal,
@@ -2306,7 +2230,7 @@ openoffice_file_save_real (GOFileSaver const *fs, IOContext *ioc,
g_object_unref (G_OBJECT (outfile));
gnm_pop_C_locale (locale);
- go_slist_free_custom (state.cell_styles, cell_styles_free);
+ g_hash_table_unref (state.cell_styles);
g_hash_table_unref (state.xl_styles);
g_hash_table_unref (state.xl_styles_neg);
g_hash_table_unref (state.xl_styles_zero);
diff --git a/src/mstyle.c b/src/mstyle.c
index e55f6c2..82dfe33 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -830,10 +830,10 @@ gnm_style_equal (GnmStyle const *a, GnmStyle const *b)
{
int i;
- if (!gnm_style_equal_XL (a, b))
- return FALSE;
if (a == b)
return TRUE;
+ if (!gnm_style_equal_XL (a, b))
+ return FALSE;
UNROLLED_FOR (i = MSTYLE_VALIDATION, i < MSTYLE_ELEMENT_MAX, i++, {
if (!ELEM_IS_EQ (a, b, i))
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]