[pango/matthiasc/for-main] layout: Allocate a bit less
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/matthiasc/for-main] layout: Allocate a bit less
- Date: Sat, 28 Aug 2021 22:41:05 +0000 (UTC)
commit c07232343aeeb7acffaad8d8dec38eb4e4b487ba
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 28 17:19:23 2021 -0400
layout: Allocate a bit less
Instead of throwing away the log_widths array
for every run, keep it around and grow it as needed.
pango/pango-layout.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index c721b41b..4235b7f3 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3601,6 +3601,7 @@ struct _ParaBreakState
int start_offset; /* Character offset of first item in state->items in layout->text */
ItemProperties properties; /* Properties for the first item in state->items */
int *log_widths; /* Logical widths for first item in state->items.. */
+ int num_log_widths; /* Length of log_widths */
int log_widths_offset; /* Offset into log_widths to the point corresponding
* to the remaining portion of the first item */
@@ -3691,8 +3692,6 @@ insert_run (PangoLayoutLine *line,
if (state->log_widths_offset > 0)
pango_glyph_string_free (state->glyphs);
state->glyphs = NULL;
- g_free (state->log_widths);
- state->log_widths = NULL;
}
line->runs = g_slist_prepend (line->runs, run);
@@ -3843,7 +3842,6 @@ process_item (PangoLayout *layout,
pango_layout_get_item_properties (item, &state->properties);
state->glyphs = shape_run (line, state, item);
- state->log_widths = NULL;
state->log_widths_offset = 0;
processing_new_item = TRUE;
@@ -3898,7 +3896,11 @@ process_item (PangoLayout *layout,
if (processing_new_item)
{
PangoGlyphItem glyph_item = {item, state->glyphs};
- state->log_widths = g_new (int, item->num_chars);
+ if (item->num_chars > state->num_log_widths)
+ {
+ state->log_widths = g_renew (int, state->log_widths, item->num_chars);
+ state->num_log_widths = item->num_chars;
+ }
pango_glyph_item_get_logical_widths (&glyph_item, layout->text, state->log_widths);
}
@@ -3998,8 +4000,6 @@ process_item (PangoLayout *layout,
{
pango_glyph_string_free (state->glyphs);
state->glyphs = NULL;
- g_free (state->log_widths);
- state->log_widths = NULL;
return BREAK_NONE_FIT;
}
@@ -4475,6 +4475,9 @@ pango_layout_check_lines (PangoLayout *layout)
state.line_height = layout->line_spacing == 0.0 ? logical.height : layout->line_spacing * height;
}
+ state.log_widths = NULL;
+ state.num_log_widths = 0;
+
do
{
int delim_len;
@@ -4546,7 +4549,6 @@ pango_layout_check_lines (PangoLayout *layout)
state.line_start_index = start - layout->text;
state.glyphs = NULL;
- state.log_widths = NULL;
/* for deterministic bug hunting's sake set everything! */
state.line_width = -1;
@@ -4582,6 +4584,8 @@ pango_layout_check_lines (PangoLayout *layout)
}
while (!done);
+ g_free (state.log_widths);
+
apply_attributes_to_runs (layout, attrs);
layout->lines = g_slist_reverse (layout->lines);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]