[gnumeric] Sheet style: optimize getting styles for a range.



commit 5084eb94d46bf2c967157d863e8ad50bc8a6bcc8
Author: Morten Welinder <terra gnome org>
Date:   Mon Aug 26 15:59:43 2013 -0400

    Sheet style: optimize getting styles for a range.
    
    Add fast pre-optimization to bring down the number of entries before
    we start messing with hashes.  Fixes #699045.

 ChangeLog         |    3 +++
 NEWS              |    1 +
 src/sheet-style.c |   24 ++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5139122..cd4fdc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 2013-08-26  Morten Welinder  <terra gnome org>
 
        * src/sheet-style.c (cell_tile_dump): New function for debugging.
+       (internal_style_list): Add fast pre-optimization to bring down the
+       number of entries before we start messing with hashes.  Fixes
+       #699045.
 
 2013-08-22  Jean Brefort  <jean brefort normalesup org>
 
diff --git a/NEWS b/NEWS
index 77d8c60..967ce94 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Andreas:
 
 Morten:
        * Fix crash on corrupted files.  [#706413]  [#706417]
+       * Fix save style performance issue.  [#699045]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.5
diff --git a/src/sheet-style.c b/src/sheet-style.c
index db4a460..91cc0af 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -2787,6 +2787,19 @@ merge_horizontal_stripes (ISL *data)
        }
 }
 
+static int
+by_col_row (GnmStyleRegion **a, GnmStyleRegion **b)
+{
+       int d;
+
+       d = (*a)->range.start.col - (*b)->range.start.col;
+       if (d)
+               return d;
+
+       d = (*a)->range.start.row - (*b)->range.start.row;
+       return d;
+}
+
 static GnmStyleList *
 internal_style_list (Sheet const *sheet, GnmRange const *r,
                     gboolean (*style_equal) (GnmStyle const *a, GnmStyle const *b),
@@ -2826,6 +2839,17 @@ internal_style_list (Sheet const *sheet, GnmRange const *r,
        if (data.style_filter ? (data.area > sheet_area) : (data.area != sheet_area))
                g_warning ("Strange size issue in internal_style_list");
 
+       /*
+        * Simple, fast optimization first.  For the file underlying
+        * bug 699045 this brings down 332688 entries to just 86.
+        */
+       if (ui = data.accum->len >= 2) {
+               g_ptr_array_sort (data.accum, (GCompareFunc)by_col_row);
+               for (ui = data.accum->len - 1; ui > 0; ui--) {
+                       try_merge_pair (&data, ui - 1, ui);
+               }
+       }
+
        /* Populate hashes.  */
        for (ui = 0; ui < data.accum->len; ui++) {
                GnmStyleRegion *sr = g_ptr_array_index (data.accum, ui);


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