Commit 86b04cd8 authored by Morten Welinder's avatar Morten Welinder

Memory: more heap allocation, less stack allocation.

parent 3ac794c8
2017-11-30 Morten Welinder <terra@gnome.org>
* src/print-cell.c (gnm_gtk_print_cell_range): Eliminate g_alloca
usage.
* src/parse-util.c (wbref_parse): Ditto.
* src/preview-grid.c (preview_grid_draw_region): Ditto.
* src/item-grid.c (item_grid_draw_region): Ditto.
* src/parser.y (yylex): Ditto.
* src/criteria.c (parse_database_criteria): Ditto.
* src/sheet-filter.c (gnm_filter_combo_apply): Use heap, not
stack, allocation.
......
2017-11-30 Morten Welinder <terra@gnome.org>
* applix-read.c (applix_sheetref_parse): Eliminate g_alloca usage.
2017-11-18 Morten Welinder <terra@gnome.org>
* Release 1.12.36
......
......@@ -241,10 +241,9 @@ applix_sheetref_parse (char const *start, Sheet **sheet, Workbook const *wb)
return start;
}
name = g_alloca (1 + end - begin);
strncpy (name, begin, end-begin);
name [end-begin] = '\0';
name = g_strndup (begin, end - begin);
*sheet = workbook_sheet_by_name (wb, name);
g_free (name);
return *sheet != NULL ? end : start;
}
......
......@@ -448,6 +448,7 @@ parse_database_criteria (GnmEvalPos const *ep, GnmValue const *database, GnmValu
int i;
int b_col, b_row, e_col, e_row;
int *field_ind;
GSList *res;
g_return_val_if_fail (VALUE_IS_CELLRANGE (criteria), NULL);
......@@ -464,7 +465,7 @@ parse_database_criteria (GnmEvalPos const *ep, GnmValue const *database, GnmValu
}
/* Find the index numbers for the columns of criterias */
field_ind = g_alloca (sizeof (int) * (e_col - b_col + 1));
field_ind = g_new (int, e_col - b_col + 1);
for (i = b_col; i <= e_col; i++) {
cell = sheet_cell_get (sheet, i, b_row);
if (cell == NULL)
......@@ -474,13 +475,17 @@ parse_database_criteria (GnmEvalPos const *ep, GnmValue const *database, GnmValu
continue;
field_ind[i - b_col] =
find_column_of_field (ep, database, cell->value);
if (field_ind[i - b_col] == -1)
if (field_ind[i - b_col] == -1) {
g_free (field_ind);
return NULL;
}
}
return parse_criteria_range (sheet, b_col, b_row + 1,
e_col, e_row, field_ind,
FALSE);
res = parse_criteria_range (sheet, b_col, b_row + 1,
e_col, e_row, field_ind,
FALSE);
g_free (field_ind);
return res;
}
/**
......
......@@ -461,6 +461,7 @@ item_grid_draw_region (GocItem const *item, cairo_t *cr,
GnmBorder const **borders, **prev_vert;
GnmBorder const *none =
sheet->hide_grid ? NULL : gnm_style_border_none ();
gpointer *sr_array_data;
GnmRange view;
GSList *merged_active, *merged_active_seen,
......@@ -547,15 +548,16 @@ item_grid_draw_region (GocItem const *item, cairo_t *cr,
* Note that this means that in some cases array [-1] is legal.
*/
n = end_col - start_col + 3; /* 1 before, 1 after, 1 fencepost */
sr_array_data = g_new (gpointer, n * 8);
style_row_init (&prev_vert, &sr, &next_sr, start_col, end_col,
g_alloca (n * 8 * sizeof (gpointer)), sheet->hide_grid);
sr_array_data, sheet->hide_grid);
/* load up the styles for the first row */
next_sr.row = sr.row = row = start_row;
sheet_style_get_row (sheet, &sr);
/* Collect the column widths */
colwidths = g_alloca (n * sizeof (int));
colwidths = g_new (int, n);
colwidths -= start_col;
for (col = start_col; col <= end_col; col++) {
ColRowInfo const *ci = sheet_col_get_info (sheet, col);
......@@ -853,6 +855,8 @@ plain_draw : /* a quick hack to deal with 142267 */
g_slist_free (merged_used); /* merges with bottom in view */
g_slist_free (merged_active_seen); /* merges with bottom the view */
g_slist_free (merged_unused); /* merges in hidden rows */
g_free (sr_array_data);
g_free (colwidths + start_col); // Offset reverts -= from above
g_return_val_if_fail (merged_active == NULL, TRUE);
return TRUE;
}
......
......@@ -923,15 +923,15 @@ wbref_parse (GnmConventions const *convs,
if (*end != ']')
return start;
/* might be too big if quoted (remember leading [' */
name = g_alloca (1 + end - start - 2);
if (num_escapes < 0) {
strncpy (name, start+1, end-start-1);
name [end-start-1] = '\0';
} else
if (num_escapes < 0)
name = g_strndup (start + 1, end - start - 1);
else {
name = g_malloc (1 + end - start - 2);
unquote (name, start+2, end-start-2);
}
tmp_wb = (*convs->input.external_wb) (convs, ref_wb, name);
g_free (name);
if (tmp_wb == NULL)
return NULL;
......
......@@ -1110,7 +1110,7 @@ yylex (void)
goto double_quote_loop;
}
s = string = (char *) g_alloca (1 + state->ptr - p);
s = string = g_malloc (1 + state->ptr - p);
while (p != state->ptr) {
if (*p == '&') {
if (!strncmp (p, "&amp;", 5)) {
......@@ -1145,7 +1145,7 @@ yylex (void)
*s = 0;
state->ptr += 6;
v = value_new_string (string);
v = value_new_string_nocopy (string);
yylval.expr = register_expr_allocation (gnm_expr_new_constant (v));
return QUOTED_STRING;
}
......
......@@ -222,6 +222,7 @@ preview_grid_draw_region (GocItem const *item, cairo_t *cr,
GnmStyle const **styles;
GnmBorder const **borders, **prev_vert;
GnmBorder const *none = pg->gridlines ? gnm_style_border_none () : NULL;
gpointer *sr_array_data;
int *colwidths = NULL;
......@@ -233,15 +234,16 @@ preview_grid_draw_region (GocItem const *item, cairo_t *cr,
* - 2 arrays of n GnmStyle const *
*/
n = end_col - start_col + 3; /* 1 before, 1 after, 1 fencepost */
sr_array_data = g_new (gpointer, n * 8);
style_row_init (&prev_vert, &sr, &next_sr, start_col, end_col,
g_alloca (n * 8 * sizeof (gpointer)), !pg->gridlines);
sr_array_data, !pg->gridlines);
/* load up the styles for the first row */
next_sr.row = sr.row = row = start_row;
pg_style_get_row (pg, &sr);
/* Collect the column widths */
colwidths = g_alloca (n * sizeof (int));
colwidths = g_new (int, n);
colwidths -= start_col;
for (col = start_col; col <= end_col; col++)
colwidths[col] = pg->defaults.col_width;
......@@ -288,6 +290,9 @@ preview_grid_draw_region (GocItem const *item, cairo_t *cr,
y += row_height;
}
g_free (sr_array_data);
g_free (colwidths + start_col); // Offset reverts -= from above
return TRUE;
}
......
......@@ -302,6 +302,7 @@ gnm_gtk_print_cell_range (cairo_t *context,
GnmStyle const **styles;
GnmBorder const **borders, **prev_vert;
GnmBorder const *none;
gpointer *sr_array_data;
int n, col, row;
double x, y, offset;
......@@ -353,8 +354,9 @@ gnm_gtk_print_cell_range (cairo_t *context,
* Note that this means that in some cases array [-1] is legal.
*/
n = end_col - start_col + 3; /* 1 before, 1 after, 1 fencepost */
sr_array_data = g_new (gpointer, n * 8);
style_row_init (&prev_vert, &sr, &next_sr, start_col, end_col,
g_alloca (n * 8 * sizeof (gpointer)), hide_grid);
sr_array_data, hide_grid);
/* load up the styles for the first row */
next_sr.row = sr.row = row = start_row;
......@@ -610,6 +612,7 @@ gnm_gtk_print_cell_range (cairo_t *context,
g_slist_free (merged_used); /* merges with bottom in view */
g_slist_free (merged_active_seen); /* merges with bottom the view */
g_slist_free (merged_unused); /* merges in hidden rows */
g_free (sr_array_data);
g_return_if_fail (merged_active == NULL);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment