[pango/matthiasc/for-main: 2/2] layout: Allocate a bit less
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/matthiasc/for-main: 2/2] layout: Allocate a bit less
- Date: Sat, 28 Aug 2021 21:21:28 +0000 (UTC)
commit 9711ae4e897f997091b0b6fccf66ac85c5927980
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 | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index c721b41b..6c9727be 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;
}
@@ -4547,6 +4547,7 @@ pango_layout_check_lines (PangoLayout *layout)
state.glyphs = NULL;
state.log_widths = NULL;
+ state.num_log_widths = 0;
/* for deterministic bug hunting's sake set everything! */
state.line_width = -1;
@@ -4582,6 +4583,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]