[gnumeric] Style: use heap, not stack, allocation.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Style: use heap, not stack, allocation.
- Date: Thu, 30 Nov 2017 16:46:48 +0000 (UTC)
commit 537a206a1e263c7225481f95bf0fd8e24c0951c9
Author: Morten Welinder <terra gnome org>
Date: Thu Nov 30 11:45:15 2017 -0500
Style: use heap, not stack, allocation.
An allocation of 4*rows pointers is a bit big for the stack if we have
16k rows.
ChangeLog | 5 +++++
src/sheet-style.c | 20 +++++++++++---------
2 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8d85b7f..ab33923 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-30 Morten Welinder <terra gnome org>
+
+ * src/sheet-style.c (sheet_style_find_conflicts): Use heap, not
+ stack, allocation.
+
2017-11-29 Morten Welinder <terra gnome org>
* src/sstest.c (enumerate_functions): Make sure function is loaded.
diff --git a/src/sheet-style.c b/src/sheet-style.c
index d04727b..3f40ee9 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -2004,6 +2004,7 @@ sheet_style_find_conflicts (Sheet const *sheet, GnmRange const *r,
{
int n, col, row, start_col, end_col;
GnmStyleRow sr;
+ gpointer *sr_array_data;
GnmStyleBorderLocation i;
gboolean known[GNM_STYLE_BORDER_EDGE_MAX];
GnmBorder const *none = gnm_style_border_none ();
@@ -2050,15 +2051,15 @@ sheet_style_find_conflicts (Sheet const *sheet, GnmRange const *r,
/* allocate then alias the arrays for easy access */
n = end_col - start_col + 2;
- sr.vertical = (GnmBorder const **)g_alloca (n *
- (3 * sizeof (GnmBorder const *) +
- sizeof (GnmStyle const *)));
- sr.top = sr.vertical + n;
- sr.bottom = sr.top + n;
- sr.styles = ((GnmStyle const **) (sr.bottom + n));
- sr.vertical -= start_col; sr.top -= start_col;
- sr.bottom -= start_col; sr.styles -= start_col;
- sr.start_col = start_col; sr.end_col = end_col;
+ g_assert (sizeof (GnmBorder *) == sizeof (gpointer));
+ g_assert (sizeof (GnmStyle *) == sizeof (gpointer));
+ sr_array_data = g_new (gpointer, n * 4);
+ sr.vertical = (GnmBorder const **)(sr_array_data - start_col);
+ sr.top = (GnmBorder const **)(sr_array_data + n - start_col);
+ sr.bottom = (GnmBorder const **)(sr_array_data + 2 * n - start_col);
+ sr.styles = (GnmStyle const **) (sr_array_data + 3 * n - start_col);
+ sr.start_col = start_col;
+ sr.end_col = end_col;
sr.hide_grid = sheet->hide_grid;
/* pretend the previous bottom had no borders */
@@ -2109,6 +2110,7 @@ sheet_style_find_conflicts (Sheet const *sheet, GnmRange const *r,
border_mask_vec (known, borders, sr.top, r->start.col, r->end.col,
GNM_STYLE_BORDER_BOTTOM);
+ g_free (sr_array_data);
return user.conflicts;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]