summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-24 00:32:57 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-08-24 00:32:57 +0000
commit8cae1c0762fa35cbe41d35a34d8e048965d287ac (patch)
tree3c4c09451241a7eaa541567ed67b4e70b3afcee7 /pango/pango-layout.c
parent4eedbae6555816752331e1712dd3661c90c65404 (diff)
parent053288e087ae8a126e1e7efd1268f740d18200b4 (diff)
downloadpango-8cae1c0762fa35cbe41d35a34d8e048965d287ac.tar.gz
Merge branch 'matthiasc/for-main' into 'main'
layout: Only recompute log_attrs when needed See merge request GNOME/pango!433
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r--pango/pango-layout.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 8f5a6363..f78d7daf 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -247,6 +247,7 @@ pango_layout_finalize (GObject *object)
layout = PANGO_LAYOUT (object);
pango_layout_clear_lines (layout);
+ g_free (layout->log_attrs);
if (layout->context)
g_object_unref (layout->context);
@@ -718,6 +719,7 @@ pango_layout_set_attributes (PangoLayout *layout,
if (layout->attrs)
pango_attr_list_ref (layout->attrs);
+ g_clear_pointer (&layout->log_attrs, g_free);
layout_changed (layout);
if (old_attrs)
@@ -1270,6 +1272,7 @@ pango_layout_set_text (PangoLayout *layout,
layout->n_chars = pango_utf8_strlen (layout->text, -1);
layout->length = strlen (layout->text);
+ g_clear_pointer (&layout->log_attrs, g_free);
layout_changed (layout);
g_free (old_text);
@@ -1471,6 +1474,7 @@ layout_changed (PangoLayout *layout)
layout->serial++;
if (layout->serial == 0)
layout->serial++;
+
pango_layout_clear_lines (layout);
}
@@ -3120,12 +3124,6 @@ pango_layout_clear_lines (PangoLayout *layout)
g_slist_free (layout->lines);
layout->lines = NULL;
layout->line_count = 0;
-
- /* This could be handled separately, since we don't need to
- * recompute log_attrs on a width change, but this is easiest
- */
- g_free (layout->log_attrs);
- layout->log_attrs = NULL;
}
layout->unknown_glyphs_count = -1;
@@ -4397,14 +4395,13 @@ pango_layout_check_lines (PangoLayout *layout)
PangoAttrIterator iter;
PangoDirection prev_base_dir = PANGO_DIRECTION_NEUTRAL, base_dir = PANGO_DIRECTION_NEUTRAL;
ParaBreakState state;
+ gboolean need_log_attrs;
check_context_changed (layout);
if (G_LIKELY (layout->lines))
return;
- g_assert (!layout->log_attrs);
-
/* For simplicity, we make sure at this point that layout->text
* is non-NULL even if it is zero length
*/
@@ -4426,7 +4423,15 @@ pango_layout_check_lines (PangoLayout *layout)
itemize_attrs = NULL;
}
- layout->log_attrs = g_new0 (PangoLogAttr, layout->n_chars + 1);
+ if (!layout->log_attrs)
+ {
+ layout->log_attrs = g_new0 (PangoLogAttr, layout->n_chars + 1);
+ need_log_attrs = TRUE;
+ }
+ else
+ {
+ need_log_attrs = FALSE;
+ }
start_offset = 0;
start = layout->text;
@@ -4507,12 +4512,13 @@ pango_layout_check_lines (PangoLayout *layout)
apply_attributes_to_items (state.items, shape_attrs);
- get_items_log_attrs (layout->text,
- start - layout->text,
- delimiter_index + delim_len,
- state.items,
- layout->log_attrs + start_offset,
- layout->n_chars + 1 - start_offset);
+ if (need_log_attrs)
+ get_items_log_attrs (layout->text,
+ start - layout->text,
+ delimiter_index + delim_len,
+ state.items,
+ layout->log_attrs + start_offset,
+ layout->n_chars + 1 - start_offset);
state.base_dir = base_dir;
state.line_of_par = 1;