summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-12-01 23:46:04 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-12-02 14:41:02 -0500
commit0254870fe834465c58f5a7d0b39fa32ffe88ad8d (patch)
tree56d36dc4bb91c63f44c0991e48d1b9ace0957fcb /pango/pango-layout.c
parent253461f9dd2984ee00216b7292e27bb910fed816 (diff)
downloadpango-0254870fe834465c58f5a7d0b39fa32ffe88ad8d.tar.gz
layout: Small optimization
Don't calculate line width the hard way when we can do it much easier.
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r--pango/pango-layout.c28
1 files changed, 3 insertions, 25 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index a9d07940..6bdf5b43 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3269,6 +3269,7 @@ pango_layout_line_leaked (PangoLayoutLine *line)
static void shape_tab (PangoLayoutLine *line,
LastTabState *tab_state,
+ int current_width,
PangoItem *item,
PangoGlyphString *glyphs);
@@ -3456,27 +3457,6 @@ get_tab_pos (PangoLayoutLine *line,
*tab_pos -= offset;
}
-static int
-line_width (PangoLayoutLine *line)
-{
- GSList *l;
- int i;
- int width = 0;
-
- /* Compute the width of the line currently - inefficient, but easier
- * than keeping the current width of the line up to date everywhere
- */
- for (l = line->runs; l; l = l->next)
- {
- PangoLayoutRun *run = l->data;
-
- for (i = 0; i < run->glyphs->num_glyphs; i++)
- width += run->glyphs->glyphs[i].geometry.width;
- }
-
- return width;
-}
-
static gboolean
showing_space (const PangoAnalysis *analysis)
{
@@ -3513,17 +3493,15 @@ struct _LastTabState {
static void
shape_tab (PangoLayoutLine *line,
LastTabState *tab_state,
+ int current_width,
PangoItem *item,
PangoGlyphString *glyphs)
{
int i, space_width;
- int current_width;
int tab_pos;
PangoTabAlign tab_align;
gunichar tab_decimal;
- current_width = line_width (line);
-
pango_glyph_string_set_size (glyphs, 1);
if (showing_space (&item->analysis))
@@ -3707,7 +3685,7 @@ shape_run (PangoLayoutLine *line,
PangoGlyphString *glyphs = pango_glyph_string_new ();
if (layout->text[item->offset] == '\t')
- shape_tab (line, &state->last_tab, item, glyphs);
+ shape_tab (line, &state->last_tab, state->line_width - state->remaining_width, item, glyphs);
else
{
PangoShapeFlags shape_flags = PANGO_SHAPE_NONE;