summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-21 00:51:19 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-23 20:02:27 -0400
commit053288e087ae8a126e1e7efd1268f740d18200b4 (patch)
tree3c4c09451241a7eaa541567ed67b4e70b3afcee7
parent4eedbae6555816752331e1712dd3661c90c65404 (diff)
downloadpango-053288e087ae8a126e1e7efd1268f740d18200b4.tar.gz
layout: Only recompute log_attrs when needed
There is no need to throw away the log_attrs when we just change the width, or other layout properties that do not affect segmentation.
-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;